AccountsServer

@accounts/serverGlobalsAccountsServer

Type parameters

CustomUser: User

Hierarchy

  • AccountsServer

Index

Constructors

Properties

Methods

Constructors

constructor

+ new AccountsServer(options: AccountsServerOptions‹CustomUser›, services: object): AccountsServer

Defined in packages/server/src/accounts-server.ts:61

Parameters:

NameType
optionsAccountsServerOptions‹CustomUser›
servicesobject

Returns: AccountsServer

Properties

options

options: AccountsServerOptions‹CustomUser› & typeof defaultOptions

Defined in packages/server/src/accounts-server.ts:58

Methods

activateUser

activateUser(userId: string): Promise‹void›

Defined in packages/server/src/accounts-server.ts:590

description Activate a user.

Parameters:

NameTypeDescription
userIdstringUser id.

Returns: Promise‹void›

  • Return a Promise.

authenticateWithService

authenticateWithService(serviceName: string, params: any, infos: ConnectionInformations): Promise‹boolean›

Defined in packages/server/src/accounts-server.ts:127

description Try to authenticate the user for a given service

throws AuthenticateWithServiceErrors

Parameters:

NameType
serviceNamestring
paramsany
infosConnectionInformations

Returns: Promise‹boolean›


createTokens

createTokens(__namedParameters: object): Promise‹Tokens›

Defined in packages/server/src/accounts-server.ts:417

description Refresh a user token.

Parameters:

__namedParameters: object

NameTypeDefaultDescription
isImpersonatedbooleanfalseShould be true if impersonating another user.
tokenstring-User session token.
userCustomUser-The user object.

Returns: Promise‹Tokens›

  • Return a new accessToken and refreshToken.

deactivateUser

deactivateUser(userId: string): Promise‹void›

Defined in packages/server/src/accounts-server.ts:581

description Deactivate a user, the user will not be able to login until his account is reactivated.

Parameters:

NameTypeDescription
userIdstringUser id.

Returns: Promise‹void›

  • Return a Promise.

findSessionByAccessToken

findSessionByAccessToken(accessToken: string): Promise‹Session›

Defined in packages/server/src/accounts-server.ts:535

description Find a session by his token.

throws FindSessionByAccessTokenErrors

Parameters:

NameType
accessTokenstring

Returns: Promise‹Session›

  • Return a session.

findUserById

findUserById(userId: string): Promise‹CustomUser | null›

Defined in packages/server/src/accounts-server.ts:572

description Find a user by his id.

Parameters:

NameTypeDescription
userIdstringUser id.

Returns: Promise‹CustomUser | null›

  • Return a user or null if not found.

getHooks

getHooks(): Emittery

Defined in packages/server/src/accounts-server.ts:104

Returns: Emittery


getOptions

getOptions(): AccountsServerOptions‹CustomUser›

Defined in packages/server/src/accounts-server.ts:100

Returns: AccountsServerOptions‹CustomUser›


getServices

getServices(): object

Defined in packages/server/src/accounts-server.ts:96

Returns: object

  • [ key: string]: AuthenticationService

impersonate

impersonate(accessToken: string, impersonated: ImpersonationUserIdentity, infos: ConnectionInformations): Promise‹ImpersonationResult›

Defined in packages/server/src/accounts-server.ts:260

description Impersonate to another user. For security reasons, even if useStatelessSession is set to true the token will be checked against the database.

throws LoginWithServiceErrors

Parameters:

NameTypeDescription
accessTokenstringUser access token.
impersonatedImpersonationUserIdentityimpersonated user.
infosConnectionInformationsUser connection informations.

Returns: Promise‹ImpersonationResult›

  • ImpersonationResult

loginWithService

loginWithService(serviceName: string, params: any, infos: ConnectionInformations): Promise‹LoginResult›

Defined in packages/server/src/accounts-server.ts:174

throws LoginWithServiceErrors

Parameters:

NameType
serviceNamestring
paramsany
infosConnectionInformations

Returns: Promise‹LoginResult›


loginWithUser

loginWithUser(user: CustomUser, infos: ConnectionInformations): Promise‹LoginResult›

Defined in packages/server/src/accounts-server.ts:229

description Server use only. This method creates a session without authenticating any user identity. Any authentication should happen before calling this function.

Parameters:

NameTypeDescription
userCustomUserThe user object.
infosConnectionInformationsUser's connection informations.

Returns: Promise‹LoginResult›

  • Session tokens and user object.

logout

logout(accessToken: string): Promise‹void›

Defined in packages/server/src/accounts-server.ts:452

description Logout a user and invalidate his session.

throws LogoutErrors

Parameters:

NameTypeDescription
accessTokenstringUser access token.

Returns: Promise‹void›

  • Return a promise.

on

on(eventName: string, callback: HookListener): function

Defined in packages/server/src/accounts-server.ts:117

Subscribe to an accounts-js event.

accountsServer.on(ServerHooks.ValidateLogin, ({ user }) => {
// This hook is called every time a user try to login
// You can use it to only allow users with verified email to login
});

Parameters:

NameType
eventNamestring
callbackHookListener

Returns: function

▸ (): void


prepareMail

prepareMail(to: string, token: string, user: CustomUser, pathFragment: string, emailTemplate: EmailTemplateType, from: string): any

Defined in packages/server/src/accounts-server.ts:594

Parameters:

NameType
tostring
tokenstring
userCustomUser
pathFragmentstring
emailTemplateEmailTemplateType
fromstring

Returns: any


refreshTokens

refreshTokens(accessToken: string, refreshToken: string, infos: ConnectionInformations): Promise‹LoginResult›

Defined in packages/server/src/accounts-server.ts:345

description Refresh a user token.

throws RefreshTokensErrors

Parameters:

NameTypeDescription
accessTokenstringUser access token.
refreshTokenstringUser refresh token.
infosConnectionInformationsUser connection informations.

Returns: Promise‹LoginResult›

  • LoginResult.

resumeSession

resumeSession(accessToken: string): Promise‹CustomUser›

Defined in packages/server/src/accounts-server.ts:480

description Resume the current session associated to the access token. Will throw if the token or the session is invalid. If useStatelessSession is false the session validity will be checked against the database.

throws ResumeSessionErrors

Parameters:

NameTypeDescription
accessTokenstringUser JWT access token.

Returns: Promise‹CustomUser›

Return the user associated to the session.


sanitizeUser

sanitizeUser(user: CustomUser): CustomUser

Defined in packages/server/src/accounts-server.ts:608

Parameters:

NameType
userCustomUser

Returns: CustomUser