Realm.User

Class for managing users.

accessToken

Gets this user's access token. This is the user's credential for accessing the MongoDB Realm Cloud and should be treated as sensitive data.

Type:
string
customData
nullable

Gets this user's associated custom data. This is application-specific data provided by the server.

Type:
object
deviceId

Gets the device id. null if no device id.

Type:
string
functions

Convenience wrapper around call_function(name, [args])

Examples::
// These are all equivalent:
await user.call_function("do_thing", [a1, a2, a3]);
await user.functions.do_thing(a1, a2, a3);
await user.functions["do_thing"](a1, a2, a3);
// It it legal to store the functions as first-class values:
const do_thing = user.functions.do_thing;
await do_thing(a1);
await do_thing(a2);
id

Gets the identity of this user on MongoDB Realm Cloud. The identity is a guaranteed to be unique among all users on MongoDB Realm Cloud .

Type:
string
identities

Gets an array of identities for this user on MongoDB Realm Cloud. Each element in the array is an object with properties userId and providerType.

Type:
[Object, ...]
isLoggedIn

Is true if the user is logged in. False otherwise.

Type:
boolean
profile

Gets the user's profile (name, email address, etc.).

Type:
object
providerType

Gets the provider type for the identity.

Type:
string
refreshToken

Gets this user's refresh token. This is the user's credential for accessing the MongoDB Realm Cloud and should be treated as sensitive data.

Type:
string
state

Gets the user's state which can be one of the following:

  • LoggedOut - the user is logged out
  • LoggedIn - the user is logged in
  • Removed - the user has been removed
Type:
string

Returns a provider to interact with API keys.

Returns: Realm.Auth.ApiKeyAuth
  • the provider
callFunction(name, args)

Calls the named server function as this user.

Parameters:
  • name
    • Type: string
    • name of the function to call

  • args
    • Type: [any, ...]
    • list of arguments to pass

linkCredentials(credentials)Promise<void>

Links a user to another credentials. This is useful when linking different account togteher.

Parameters:
Returns: Promise<void>
  • resolves when the user has been linked with the other credentials.
logOut()Promise<void>

Logs out the user.

Returns: Promise<void>
  • resolves when the user has been logged out
mongoClient(serviceName)MongoDB

Returns a connection to the MongoDB service.

Parameters:
  • serviceName
    • Type: string
Returns: MongoDB
Example:
let blueWidgets = user.mongoClient('myClusterName')
                      .db('myDb')
                      .collection('widgets')
                      .find({color: 'blue'});
push(serviceName)Push

Access the operations of the push service.

Parameters:
  • serviceName
    • Type: string
Returns: Push
refreshCustomData()Promise<Object>

Refresh user's custom data.

See: {Realm.User.customData}
Returns: Promise<Object>