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 callFunction(name, [args])

Examples::
// These are all equivalent:
await user.callFunction("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 id of this user on Atlas App Services. The id is a guaranteed to be unique among all users on Atlas App Services.

Type:
string
identities

Gets an array of identities for this user.

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:
ProviderType
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
addListener(callback)

Adds a listener that will be fired on various user related events. This includes auth token refresh, refresh token refresh, refresh custom user data, and logout.

Parameters:
  • callback
    • Type: function

Returns a provider to interact with API keys.

Returns: Realm.Auth.ApiKeyAuth
  • the provider
callFunction(name, args)Promise<any>

Calls the named server function as this user.

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

  • args optional repeatable
    • Type: *
    • arguments to pass to the function

Returns: Promise<any>
  • resolves when the function terminates.
linkCredentials(credentials)Promise<void>

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

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>
removeAllListeners()

Removes all event listeners

removeListener(callback)

Removes an event listener (see addListener)

Parameters:
  • callback
    • Type: function