public class User extends Object
The user is used to configure Synchronized Realms and gives access to calling Realm App Functions
through Functions
and accessing remote Realm App Mongo Databases through a
MongoClient
.
App.login(Credentials)
,
io.realm.mongodb.sync.SyncConfiguration.Builder#Builder(User, String)
Modifier and Type | Class and Description |
---|---|
static class |
User.State
The user's potential states.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Two Users are considered equal if they have the same user identity and are associated
with the same app.
|
String |
getAccessToken()
Returns the current access token for the user.
|
ApiKeyAuth |
getApiKeys()
Returns a wrapper for managing API keys controlled by the current user.
|
App |
getApp()
Returns the
App this user is associated with. |
Document |
getCustomData()
Return the custom user data associated with the user in the Realm App.
|
String |
getDeviceId()
Returns a unique identifier for the device the user logged in to.
|
Functions |
getFunctions()
Returns a functions manager for invoking MongoDB Realm Functions.
|
Functions |
getFunctions(CodecRegistry codecRegistry)
Returns a functions manager for invoking Realm Functions with custom
codec registry for encoding and decoding arguments and results.
|
String |
getId()
Returns the server id of the user.
|
List<UserIdentity> |
getIdentities()
Returns a new list of the user's identities.
|
MongoClient |
getMongoClient(String serviceName)
Returns a
MongoClient instance for accessing documents in the database. |
UserProfile |
getProfile()
Returns the profile for this user.
|
Credentials.Provider |
getProviderType()
Returns the provider type used to log the user
|
Push |
getPush(String serviceName)
Returns the
Push instance for managing push notification registrations. |
String |
getRefreshToken()
Returns the current refresh token for the user.
|
User.State |
getState()
Returns the
User.State the user is in. |
int |
hashCode() |
boolean |
isLoggedIn()
Returns true if the user is currently logged in.
|
User |
linkCredentials(Credentials credentials)
Links the current user with a new user identity represented by the given credentials.
|
RealmAsyncTask |
linkCredentialsAsync(Credentials credentials,
App.Callback<User> callback)
Links the current user with a new user identity represented by the given credentials.
|
void |
logOut()
Log the user out of the Realm App.
|
RealmAsyncTask |
logOutAsync(App.Callback<User> callback)
Log the user out of the Realm App asynchronously.
|
Document |
refreshCustomData()
Re-fetch custom user data from the Realm App.
|
RealmAsyncTask |
refreshCustomData(App.Callback<Document> callback)
Re-fetch custom user data from the Realm App asynchronously.
|
public String getId()
public UserProfile getProfile()
public List<UserIdentity> getIdentities()
UserIdentity
public Credentials.Provider getProviderType()
public String getAccessToken()
public String getRefreshToken()
public String getDeviceId()
public App getApp()
App
this user is associated with.App
this user is associated with.public User.State getState()
User.State
the user is in.User.State
of the user.public Document getCustomData()
The data is only refreshed when the user's access token is refreshed or when explicitly
calling refreshCustomData()
.
public Document refreshCustomData()
AppException
- if the request failed in some way.public RealmAsyncTask refreshCustomData(App.Callback<Document> callback)
This is the asynchronous variant of refreshCustomData()
.
callback
- The callback that will receive the result or any errors from the request.IllegalStateException
- if not called on a looper thread.public boolean isLoggedIn()
true
if still logged in, false
if not.public User linkCredentials(Credentials credentials)
Linking a user with more credentials, mean the user can login either of these credentials. It also makes it possible to "upgrade" an anonymous user by linking it with e.g. Email/Password credentials.
// Example
App app = new App("app-id")
User user = app.login(Credentials.anonymous());
user.linkCredentials(Credentials.emailPassword("email", "password"));
Note: It is not possible to link two existing users of MongoDB Realm. The provided credentials must not have been used by another user.
credentials
- the credentials to link with the current user.User
the credentials were linked to.IllegalStateException
- if no user is currently logged in.public RealmAsyncTask linkCredentialsAsync(Credentials credentials, App.Callback<User> callback)
Linking a user with more credentials, mean the user can login either of these credentials. It also makes it possible to "upgrade" an anonymous user by linking it with e.g. Email/Password credentials.
// Example
App app = new App("app-id")
User user = app.login(Credentials.anonymous());
user.linkCredentials(Credentials.emailPassword("email", "password"));
Note: It is not possible to link two existing users of MongoDB Realm. The provided credentials must not have been used by another user.
credentials
- the credentials to link with the current user.callback
- callback when user identities has been linked or it failed. The callback will
always happen on the same thread as this method is called on.IllegalStateException
- if called from a non-looper thread.public void logOut() throws AppException
Once the Realm App has confirmed the logout any registered AuthenticationListener
will be notified and user credentials will be deleted from this device.
Logging out anonymous users will remove them immediately instead of marking them as
User.State.LOGGED_OUT
. All other users will be marked as User.State.LOGGED_OUT
and will still be returned by App.allUsers()
. They can be removed completely by calling
App#removeUser(User
()}.
AppException
- if an error occurred while trying to log the user out of the Realm
App.public RealmAsyncTask logOutAsync(App.Callback<User> callback)
Once the Realm App has confirmed the logout any registered AuthenticationListener
will be notified and user credentials will be deleted from this device.
Logging out anonymous users will remove them immediately instead of marking them as
User.State.LOGGED_OUT
. All other users will be marked as User.State.LOGGED_OUT
and will still be returned by App.allUsers()
. They can be removed completely by calling
App.removeUser(User)
()}.
callback
- callback when logging out has completed or failed. The callback will always
happen on the same thread as this method is called on.IllegalStateException
- if called from a non-looper thread.public ApiKeyAuth getApiKeys()
IllegalStateException
- if no user is currently logged in.public Functions getFunctions()
This will use the associated app's default codec registry to encode and decode arguments and results.
Functions
public Functions getFunctions(CodecRegistry codecRegistry)
codecRegistry
- The codec registry to use for encoding and decoding arguments and results
towards the remote Realm App.Functions
public Push getPush(String serviceName)
Push
instance for managing push notification registrations.serviceName
- the service name used to connect to the server.public MongoClient getMongoClient(String serviceName)
MongoClient
instance for accessing documents in the database.serviceName
- the service name used to connect to the server.public boolean equals(Object o)