Realm.Sync.User

Class for managing Sync users.

Related Classes

PermissionChange
PermissionOffer
PermissionOfferResponse
Realm.Sync.User.all
static

A dictionary containing users that are currently logged in. The keys in the dictionary are user identities, values are corresponding User objects.

Type:
object
Realm.Sync.User.current
static

Get the currently logged in user. Throws error if > 1 user logged in, returns undefined if no users logged in.

Type:
User
identity

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

Type:
string
isAdmin

Returns true if this user is an administrator.

Type:
bool
isAdminToken

Returns true if the token is an administrator token.

server

Gets the server URL that was used for authentication.

Type:
string
token

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

Type:
string
Realm.Sync.User.adminUser()
staticDeprecated: to be removed in future versions. Use User.login(server, Credentials.adminToken) instead.
Realm.Sync.User.authenticate()
staticDeprecated: to be removed in future versions. Use User.login(server, Credentials.SOME-PROVIDER) instead.
Realm.Sync.User.completePasswordReset(server, resetToken, newPassword)Promise<void>
static

Complete the password reset flow by using the reset token sent to the user's email as a one-time authorization token to change the password.

By default, Realm Object Server will send a link to the user's email that will redirect to a webpage where they can enter their new password. If you wish to provide a native UX, you may wish to modify the password authentication provider to use a custom URL with deep linking, so you can open the app, extract the token, and navigate to a view that allows to change the password within the app.

Parameters:
  • server
    • Type: string
    • authentication server

  • resetToken
    • Type: string
    • The token that was sent to the user's email address.

  • newPassword
    • Type: string
    • The user's new password.

Returns: Promise<void> A promise which is resolved when the request has been sent.
Realm.Sync.User.confirmEmail(server, confirmationToken)Promise<void>
static

Complete the email confirmation flow by using the confirmation token sent to the user's email as a one-time authorization token to confirm their email.

By default, Realm Object Server will send a link to the user's email that will redirect to a webpage where they can enter their new password. If you wish to provide a native UX, you may wish to modify the password authentication provider to use a custom URL with deep linking, so you can open the app, extract the token, and navigate to a view that allows to confirm the email within the app.

Parameters:
  • server
    • Type: string
    • authentication server

  • confirmationToken
    • Type: string
    • The token that was sent to the user's email address.

Returns: Promise<void> A promise which is resolved when the request has been sent.
Realm.Sync.User.deserialize(serialized)
static

Creates a new sync user instance from the serialized representation.

Parameters:
  • serialized
    • Type: object
    • the serialized version of the user, obtained by calling User#serialize.

Realm.Sync.User.login(server, credentials)Promise<User> or User
static

Logs the user in to the Realm Object Server.

Parameters:
  • server
    • Type: string
    • The url of the server that the user is authenticated against.

  • credentials
    • Type: Credentials
    • The credentials to use for authentication. Obtain them by calling one of the Credentials static methods.

Returns: Promise<User> or User A User object if the credentials are adminToken, Promise<User> otherwise.
Realm.Sync.User.register()
staticDeprecated: to be removed in future versions. Use User.login(server, Credentials.usernamePassword) instead.
Realm.Sync.User.registerWithProvider()
staticDeprecated: to be removed in future versions. Use User.login(server, Credentials.SOME-PROVIDER) instead.
Realm.Sync.User.requestEmailConfirmation(server, email)Promise<void>
static

Request an email confirmation email to be sent to a user's email. This will not throw an exception, even if the email doesn't belong to a Realm Object Server user.

Parameters:
  • server
    • Type: string
    • authentication server

  • email
    • Type: string
    • The email that corresponds to the user's username.

Returns: Promise<void> A promise which is resolved when the request has been sent.
Realm.Sync.User.requestPasswordReset(server, email)Promise<void>
static

Request a password reset email to be sent to a user's email. This will not throw an exception, even if the email doesn't belong to a Realm Object Server user.

This can only be used for users who authenticated with the 'password' provider, and passed a valid email address as a username.

Parameters:
  • server
    • Type: string
    • authentication server

  • email
    • Type: string
    • The email that corresponds to the user's username.

Returns: Promise<void> A promise which is resolved when the request has been sent.
acceptPermissionOffer(token)string

Consumes a token generated by offerPermissions to obtain permissions to a shared Realm.

Parameters:
  • token
    • Type: string
    • The token, generated by User.offerPermissions

Returns: string The url of the Realm that the token has granted permissions to.
applyPermissions(condition, realmUrl, accessLevel)Promise

Changes the permissions of a Realm.

Parameters:
  • condition
    • Type: object
    • A condition that will be used to match existing users against. This should be an object, containing either the key 'userId', or 'metadataKey' and 'metadataValue'.

  • realmUrl
    • Type: string
    • The path to the Realm that you want to apply permissions to.

  • accessLevel
    • Type: string
    • The access level you want to set: 'none', 'read', 'write' or 'admin'.

Returns: Promise a Promise that, upon completion, indicates that the permissions have been successfully applied by the server. It will be resolved with the PermissionChange object that refers to the applied permission.
createConfiguration(config)Realm.Configuration

Creates the configuration object required to open a synchronized Realm.

Parameters:
  • config
    • Type: Realm.PartialConfiguration
    • optional parameters that should override any default settings.

Returns: Realm.Configuration the full Realm configuration
getGrantedPermissions(recipient)Promise

Asynchronously retrieves all permissions associated with the user calling this method.

Parameters:
  • recipient
    • Type: string
    • the optional recipient of the permission. Can be either 'any' which is the default, or 'currentUser' or 'otherUser' if you want only permissions belonging to the user or not belonging to the user.

Returns: Promise a Promise with a queryable collection of permission objects that provides detailed information regarding the granted access. The collection is a live query similar to what you would get by callig Realm.objects, so the same features apply - you can listen for notifications or filter it.
invalidatePermissionOffer(permissionOfferOrToken)

Invalidates a permission offer. Invalidating an offer prevents new users from consuming its token. It doesn't revoke any permissions that have already been granted.

Parameters:
  • permissionOfferOrToken
    • Type: string or PermissionOffer
    • Either the token or the entire PermissionOffer object that was generated with offerPermissions.

logout()

Logs out the user from the Realm Object Server.

offerPermissions(realmUrl, accessLevel, expiresAt)string

Generates a token that can be used for sharing a Realm.

Parameters:
  • realmUrl
    • Type: string
    • The Realm URL whose permissions settings should be changed. Use * to change the permissions of all Realms managed by this user.

  • accessLevel
    • Type: string
    • The access level to grant matching users. Note that the access level setting is additive, i.e. you cannot revoke permissions for users who previously had a higher access level. Can be 'read', 'write' or 'admin'.

  • expiresAt optional
    • Type: Date
    • Optional expiration date of the offer. If set to null, the offer doesn't expire.

Returns: string
  • A token that can be shared with another user, e.g. via email or message and then consumed by User.acceptPermissionOffer to obtain permissions to a Realm.
openManagementRealm()Realm

Get the management realm for this User. This Realm can be used to control access and permissions for Realms owned by the user. This includes giving others access to the Realms.

Returns: Realm
retrieveAccount(provider, username)Promise

Get account information for a user. (requires administrator privilidges)

Parameters:
  • provider
    • Type: string
    • the provider to query for user account information (ex. 'password')

  • username
    • Type: string
    • the target username which account information should be retrieved

Returns: Promise
  • a promise that will be resolved with the retrieved account information as JSON object
Example:
{
  "provider_id": "[email protected]",
  "provider": "password",
      "user": {
          "id": "06ac9a0a-a96a-4ee1-b53c-b05a7542035a",
          "isAdmin": true,
      }
}
serialize()object

Serializes a user to an object, that can be persisted or passed to another component to create a new instance by calling User.deserialize. The serialized user instance includes the user's refresh token and should be treated as sensitive data.

Returns: object an object, containing the user identity, server url, and refresh token.