Home Reference Source
public class | source

AuthContainer

Direct Subclass:

CloudCodeAuthContainer

Auth container

Provides User authentications and user roles API.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

accessToken: String

Current access token

public get

Currently logged-in user

Method Summary

Public Methods
public

async adminDisableUser(userOrUserID: Record | String, message: String, expiry: Date): Promise<String>

Disable user account of a user.

public

async adminEnableUser(userOrUserID: Record | String): Promise<String>

Enable user account of a user.

public

async adminResetPassword(userOrUserID: Record | String, newPassword: String): Promise<String>

Reset user password, require master key.

public

async assignUserRole(usersOrUserIDs: Record[] | String[], rolesOrRoleNames: Role[] | String[]): Promise<String[]>

Assigns roles to users.

public

async changePassword(oldPassword: String, newPassword: String, invalidate: Boolean): Promise<Record>

Changes the password of the current user.

public

async fetchUserRole(usersOrUserIDs: Record[] | String[]): Promise<Object>

Gets roles of users from server.

public

async login(authData: Object, password: String): Promise<Record>

Logs in to an existing user account with the specified auth data and password.

public

async loginWithEmail(email: String, password: String): Promise<Record>

Logs in to an existing user account with the specified email and password.

public

async loginWithProvider(provider: String, authData: Object): Promise<Record>

Logs in to an existing user account with custom auth provider.

public

async loginWithUsername(username: String, password: String): Promise<Record>

Logs in to an existing user account with the specified username and password.

public

async logout(): Promise

Logs out the current user of this container.

public

onUserChanged(listener: function()): EventHandle

Registers listener which user record changed.

public

async revokeUserRole(usersOrUserIDs: Record[] | String[], rolesOrRoleNames: Role[] | String[]): Promise<String[]>

Revokes roles from users.

public

async setAdminRole(roles: Role[]): Promise<String[]>

Defines roles to have admin right.

public

async setDefaultRole(roles: Role[]): Promise<String[]>

Sets default roles for new registered users.

public

async signup(authData: Object, password: String, data: Object): Promise<Record>

Creates a user account with the specified auth data, password and user record data.

public

async signupAnonymously(): Promise<Record>

Creates an anonymous user account and log in as the created user.

public

async signupWithEmail(email: String, password: String, data: Object): Promise<Record>

Creates a user account with the specified email, password and user record data.

public

async signupWithUsername(username: String, password: String, data: Object): Promise<Record>

Creates a user account with the specified username, password and user record data.

public

async whoami(): Promise<Record>

Retrieves current user record from server.

Public Constructors

public constructor() source

Public Members

public get accessToken: String source

Current access token

public get currentUser: Record source

Currently logged-in user

Public Methods

public async adminDisableUser(userOrUserID: Record | String, message: String, expiry: Date): Promise<String> source

Disable user account of a user.

This function is intended for admin use.

Params:

NameTypeAttributeDescription
userOrUserID Record | String

target user or user ID

message String
  • optional

message to be shown to user

expiry Date
  • optional

date and time when the user is automatically enabled

Return:

Promise<String>

promise with target user ID

public async adminEnableUser(userOrUserID: Record | String): Promise<String> source

Enable user account of a user.

This function is intended for admin use.

Params:

NameTypeAttributeDescription
userOrUserID Record | String

target user or user ID

Return:

Promise<String>

promise with target user ID

public async adminResetPassword(userOrUserID: Record | String, newPassword: String): Promise<String> source

Reset user password, require master key.

Params:

NameTypeAttributeDescription
userOrUserID Record | String

target user or user ID

newPassword String

new password of target user

Return:

Promise<String>

promise with target user ID

public async assignUserRole(usersOrUserIDs: Record[] | String[], rolesOrRoleNames: Role[] | String[]): Promise<String[]> source

Assigns roles to users.

Params:

NameTypeAttributeDescription
usersOrUserIDs Record[] | String[]

target users or user IDs

rolesOrRoleNames Role[] | String[]

roles or role names to be assigned

Return:

Promise<String[]>

promise with the target user IDs

public async changePassword(oldPassword: String, newPassword: String, invalidate: Boolean): Promise<Record> source

Changes the password of the current user.

Params:

NameTypeAttributeDescription
oldPassword String

old password of current user

newPassword String

new password of current user

invalidate Boolean
  • optional
  • default: false

not implemented

Return:

Promise<Record>

promise with current user record

public async fetchUserRole(usersOrUserIDs: Record[] | String[]): Promise<Object> source

Gets roles of users from server.

Params:

NameTypeAttributeDescription
usersOrUserIDs Record[] | String[]

user records or user IDs

Return:

Promise<Object>

promise with userID-to-roles map

public async login(authData: Object, password: String): Promise<Record> source

Logs in to an existing user account with the specified auth data and password.

Params:

NameTypeAttributeDescription
authData Object

unique identifier of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

public async loginWithEmail(email: String, password: String): Promise<Record> source

Logs in to an existing user account with the specified email and password.

Params:

NameTypeAttributeDescription
email String

email of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

public async loginWithProvider(provider: String, authData: Object): Promise<Record> source

Logs in to an existing user account with custom auth provider.

Params:

NameTypeAttributeDescription
provider String

provider name

authData Object

provider auth data

Return:

Promise<Record>

promise with the logged in user record

public async loginWithUsername(username: String, password: String): Promise<Record> source

Logs in to an existing user account with the specified username and password.

Params:

NameTypeAttributeDescription
username String

username of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

public async logout(): Promise source

Logs out the current user of this container.

Return:

Promise

promise

public onUserChanged(listener: function()): EventHandle source

Registers listener which user record changed.

Params:

NameTypeAttributeDescription
listener function()

Return:

EventHandle

public async revokeUserRole(usersOrUserIDs: Record[] | String[], rolesOrRoleNames: Role[] | String[]): Promise<String[]> source

Revokes roles from users.

Params:

NameTypeAttributeDescription
usersOrUserIDs Record[] | String[]

target users or user IDs

rolesOrRoleNames Role[] | String[]

roles or role names to be revoked

Return:

Promise<String[]>

promise with target user IDs

public async setAdminRole(roles: Role[]): Promise<String[]> source

Defines roles to have admin right.

Params:

NameTypeAttributeDescription
roles Role[]

roles to have admin right

Return:

Promise<String[]>

promise with role names

public async setDefaultRole(roles: Role[]): Promise<String[]> source

Sets default roles for new registered users.

Params:

NameTypeAttributeDescription
roles Role[]

default roles

Return:

Promise<String[]>

promise with role names

public async signup(authData: Object, password: String, data: Object): Promise<Record> source

Creates a user account with the specified auth data, password and user record data.

Params:

NameTypeAttributeDescription
authData Object

unique identifier of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with created user record

public async signupAnonymously(): Promise<Record> source

Creates an anonymous user account and log in as the created user.

Return:

Promise<Record>

promise with the created user record

public async signupWithEmail(email: String, password: String, data: Object): Promise<Record> source

Creates a user account with the specified email, password and user record data.

Params:

NameTypeAttributeDescription
email String

email of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with the created user record

public async signupWithUsername(username: String, password: String, data: Object): Promise<Record> source

Creates a user account with the specified username, password and user record data.

Params:

NameTypeAttributeDescription
username String

username of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with the created user record

public async whoami(): Promise<Record> source

Retrieves current user record from server.

Return:

Promise<Record>

promise with current user record