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:60

Parameters:

NameType
optionsAccountsServerOptions‹CustomUser›
servicesobject

Returns: AccountsServer

Properties

options

options: AccountsServerOptions‹CustomUser› & typeof defaultOptions

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

Methods

activateUser

activateUser(userId: string): Promise‹void›

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

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:126

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:418

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:565

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:519

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:556

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:103

Returns: Emittery


getOptions

getOptions(): AccountsServerOptions‹CustomUser›

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

Returns: AccountsServerOptions‹CustomUser›


getServices

getServices(): object

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

Returns: object

  • [ key: string]: AuthenticationService

impersonate

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

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

description Impersonate to another user.

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:173

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:228

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:453

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:116

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:578

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:476

throws ResumeSessionErrors

Parameters:

NameType
accessTokenstring

Returns: Promise‹CustomUser›


sanitizeUser

sanitizeUser(user: CustomUser): CustomUser

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

Parameters:

NameType
userCustomUser

Returns: CustomUser