Realm.Sync.User

Class for logging in and 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(adminToken, server)User
static

Create an admin user for the given authentication server with an existing token

Parameters:
  • adminToken
    • Type: string
    • existing admin token

  • server
    • Type: string
    • authentication server

Returns: User
  • admin user populated with the given token and server
Realm.Sync.User.authenticate(server, provider, options)Promise<User>
static

Authenticate a sync user with provider.

Parameters:
  • server
    • Type: string
    • authentication server

  • provider
    • Type: string
    • the provider (curently: 'password', and 'jwt')

  • options
    • Type: object
    • options used by provider:

      • jwt - token; a JWT token
      • password - username and password
Returns: Promise<User> Returns a promise with a user
Realm.Sync.User.completePasswordReset(server, reset_token, new_password)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

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

  • new_password
    • 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, confirmation_token)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

  • confirmation_token
    • 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.login(server, username, password, callback)void or Promise<User>
static

Login a sync user with username and password.

Parameters:
  • server
    • Type: string
    • authentication server

  • username
    • Type: string
  • password
    • Type: string
  • callback optional
    • Type: function
    • called with the following arguments:

      • error - an Error object is provided on failure
      • user - a valid User object on success
Returns: void or Promise<User> Returns a promise with a user if the callback was not specified
Realm.Sync.User.register(server, username, password, callback)void or Promise<User>
static

Register a sync user with username and password.

Parameters:
  • server
    • Type: string
    • authentication server

  • username
    • Type: string
  • password
    • Type: string
  • callback optional
    • Type: function
    • called with the following arguments:

      • error - an Error object is provided on failure
      • user - a valid User object on success
Returns: void or Promise<User> Returns a promise with a user if the callback was not specified
Realm.Sync.User.registerWithProvider(server, options, callback)void or Promise<User>
static

Register/login a sync user using an external login provider.

Parameters:
  • server
    • Type: string
    • authentication server

  • options
    • Type: object
    • options, containing the following:

      • provider
        • Type: string
        • The provider type

      • providerToken
        • Type: string
        • The access token for the given provider

      • userInfo optional
        • Type: object
        • A map containing additional data required by the provider

  • callback optional
    • Type: function
    • an optional callback called with the following arguments:

      • error - an Error object is provided on failure
      • user - a valid User object on success
Returns: void or Promise<User> Returns a promise with a user if the callback was not specified
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,
      }
}