Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ / /

Class User

On this page

  • io.realm.mongodb
  • Nested Class Summary
  • Method Summary
  • Inherited Methods
  • Method Detail
  • equals
  • getAccessToken
  • getApiKeys
  • getApp
  • getCustomData
  • getDeviceId
  • getFunctions
  • getId
  • getIdentities
  • getMongoClient
  • getProfile
  • getProviderType
  • getPush
  • getRefreshToken
  • getState
  • hashCode
  • isLoggedIn
  • linkCredentials
  • linkCredentialsAsync
  • logOut
  • logOutAsync
  • refreshCustomData
  • remove
  • removeAsync
java.lang.Object
io.realm.mongodb.User

A user holds the user's meta data and tokens for accessing Realm App functionality.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 .

Tip

See also:

  • App.login(Credentials)

  • io.realm.mongodb.sync.SyncConfiguration.Builder.Builder(User, String)

Modifier and Type
Class and Description
public static final
Modifier and Type
Method and Description
public boolean

Two Users are considered equal if they have the same user identity and are associated with the same app.

public String

Returns the current access token for the user.

public synchronized ApiKeyAuth

Returns a wrapper for managing API keys controlled by the current user.

public App

Returns the App this user is associated with.

public Document

Return the custom user data associated with the user in the Realm App.

public String

Returns a unique identifier for the device the user logged in to.

public Functions
CodecRegistry codecRegistry
)

Returns a functions manager for invoking Realm Functions with custom codec registry for encoding and decoding arguments and results.

public synchronized Functions

Returns a functions manager for invoking MongoDB Realm Functions.

public String

Returns the server id of the user.

public List

Returns a new list of the user's identities.

public synchronized MongoClient
String serviceName
)

Returns a MongoClient instance for accessing documents in the database.

Returns the profile for this user.

Returns the provider type used to log the user

public synchronized Push
String serviceName
)

Returns the Push instance for managing push notification registrations.

public String

Returns the current refresh token for the user.

public User.State

Returns the State the user is in.

public int
public boolean

Returns true if the user is currently logged in.

public User

Links the current user with a new user identity represented by the given credentials.

Links the current user with a new user identity represented by the given credentials.

public void

Log the user out of the Realm App.

Log the user out of the Realm App asynchronously.

Re-fetch custom user data from the Realm App asynchronously.

public Document

Re-fetch custom user data from the Realm App.

public User

Calling this will remove the user and any Realms the user has from the device.

Calling this will asynchronously remove the user and any Realms the user has from the device.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public boolean equals (
)

Two Users are considered equal if they have the same user identity and are associated with the same app.

Overrides

equals in class Object

Returns the current access token for the user.

Returns

the current access token.

public synchronized ApiKeyAuth getApiKeys ()

Returns a wrapper for managing API keys controlled by the current user.

Returns

wrapper for managing API keys controlled by the current user.

Throws

public App getApp ()

Returns the App this user is associated with.

Returns

the App this user is associated with.

public Document getCustomData ()

Return the custom user data associated with the user in the Realm App.The data is only refreshed when the user's access token is refreshed or when explicitly calling refreshCustomData() .

Returns

The custom user data associated with the user.

Returns a unique identifier for the device the user logged in to.

Returns

a unique device identifier for the user.

CodecRegistry codecRegistry
)

Returns a functions manager for invoking Realm Functions with custom codec registry for encoding and decoding arguments and results.

Parameters

  • codecRegistry - The codec registry to use for encoding and decoding arguments and results towards the remote Realm App.

Tip

See also:

public synchronized Functions getFunctions ()

Returns a functions manager for invoking MongoDB Realm Functions.This will use the associated app's default codec registry to encode and decode arguments and results.

Tip

See also:

public String getId ()

Returns the server id of the user.

Returns

the server id of the user.

Returns a new list of the user's identities.

Returns

the list of identities.

Tip

See also:

public synchronized MongoClient getMongoClient (
String serviceName
)

Returns a MongoClient instance for accessing documents in the database.

Parameters

  • serviceName - the service name used to connect to the server.

Returns the profile for this user.

Returns

the profile for this user

Returns the provider type used to log the user

Returns

the provider type of the user

public synchronized Push getPush (
String serviceName
)

Returns the Push instance for managing push notification registrations.

Parameters

  • serviceName - the service name used to connect to the server.

Returns the current refresh token for the user.

Returns

the current refresh token.

Returns the State the user is in.

Returns

the State of the user.

public int hashCode ()

Overrides

hashCode in class Object

public boolean isLoggedIn ()

Returns true if the user is currently logged in. Returns whether or not this user is still logged into the MongoDB Realm App.

Returns

true if still logged in, false if not.

Credentials credentials
)

Links the current user with a new user identity represented by the given 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.

Parameters

  • credentials - the credentials to link with the current user.

Returns

the User the credentials were linked to.

Throws

Links the current user with a new user identity represented by the given 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.

Parameters

  • 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.

Throws

public void logOut ()

Log the user out of the Realm App. This will unregister them on the device and stop any synchronization to and from the users' Realms. Any Realms owned by the user will not be deleted from the device before User.remove() is called.

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 User.remove() .

Throws

  • AppException - if an error occurred while trying to log the user out of the Realm App.

Log the user out of the Realm App asynchronously. This will unregister them on the device and stop any synchronization to and from the users' Realms. Any Realms owned by the user will not be deleted from the device before User.remove() is called.

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 User.remove() .

Parameters

  • callback - callback when logging out has completed or failed. The callback will always happen on the same thread as this method is called on.

Throws

Re-fetch custom user data from the Realm App asynchronously.This is the asynchronous variant of refreshCustomData() .

Parameters

  • callback - The callback that will receive the result or any errors from the request.

Returns

The task representing the ongoing operation.

Throws

public Document refreshCustomData ()

Re-fetch custom user data from the Realm App.

Returns

The updated custom user data associated with the user.

Throws

public User remove ()

Calling this will remove the user and any Realms the user has from the device. No data is removed from the server. If the user is logged in when calling this method, the user is logged out before any data is deleted.

Returns

the user that was removed.

Throws

  • AppException - if an error occurred while trying to remove the user.

Calling this will asynchronously remove the user and any Realms the user has from the device. No data is removed from the server. If the user is logged in when calling this method, the user is logged out before any data is deleted.

Parameters

  • callback - callback when removing the user has completed or failed. The callback will always happen on the same thread as this method is called on.

Throws

Back

RealmResultTask