Realm.Sync.User

Class for logging in and managing Sync users.

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
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.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
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.
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
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,
      }
}