Skip to main content

AccountsServer <CustomUser>

Index

Constructors

constructor

Properties

publiccontext

context: ExecutionContext

publicoptions

options: AccountsServerOptions<CustomUser> & { ambiguousErrorMessages: boolean; createNewSessionTokenOnRefresh: boolean; emailTemplates: EmailTemplatesType; enableAutologin: boolean; micro: boolean; sendMail: (mail: object) => Promise<void>; siteUrl: string; tokenConfigs: { accessToken: { expiresIn: string }; refreshToken: { expiresIn: string } }; tokenSecret: string | { privateKey: Secret; publicKey: Secret }; useInternalUserObjectSanitizer: boolean; useStatelessSession: boolean; userObjectSanitizer: <CustomUser>(user: CustomUser) => CustomUser }

publicservices

services: AuthenticationServices<CustomUser> | Record<string, new (args: any) => AuthenticationService<CustomUser>>

Methods

publicactivateUser

  • activateUser(userId: string): Promise<void>
  • @description

    Activate a user.


    Parameters

    • userId: string

      User id.

    Returns Promise<void>

    • Return a Promise.

publicauthenticateWithService

  • authenticateWithService(serviceName: string, params: any, infos: ConnectionInformations): Promise<boolean>
  • @description

    Try to authenticate the user for a given service

    @throws

    Parameters

    • serviceName: string
    • params: any
    • infos: ConnectionInformations

    Returns Promise<boolean>

publiccreateTokens

  • createTokens(__namedParameters: { isImpersonated?: boolean; token: string; user: CustomUser }): Promise<Tokens>
  • @description

    Refresh a user token.


    Parameters

    • __namedParameters: { isImpersonated?: boolean; token: string; user: CustomUser }

    Returns Promise<Tokens>

    • Return a new accessToken and refreshToken.

publicdeactivateUser

  • deactivateUser(userId: string): Promise<void>
  • @description

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


    Parameters

    • userId: string

      User id.

    Returns Promise<void>

    • Return a Promise.

publicfindSessionByAccessToken

  • findSessionByAccessToken(accessToken: string): Promise<Session>

publicfindUserById

  • findUserById(userId: string): Promise<null | CustomUser>
  • @description

    Find a user by his id.


    Parameters

    • userId: string

      User id.

    Returns Promise<null | CustomUser>

    • Return a user or null if not found.

publicgetHooks

  • getHooks(): Emittery<Record<PropertyKey, any>, Record<PropertyKey, any> & _OmnipresentEventData, DatalessEventNames<Record<PropertyKey, any>>>
  • Returns Emittery<Record<PropertyKey, any>, Record<PropertyKey, any> & _OmnipresentEventData, DatalessEventNames<Record<PropertyKey, any>>>

publicgetOptions

publicgetServices

publicimpersonate

  • impersonate(accessToken: string, impersonated: ImpersonationUserIdentity, infos: ConnectionInformations): Promise<ImpersonationResult>
  • @description

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

    @throws

    Parameters

    • accessToken: string

      User access token.

    • impersonated: ImpersonationUserIdentity

      impersonated user.

    • infos: ConnectionInformations

      User connection informations.

    Returns Promise<ImpersonationResult>

    • ImpersonationResult

publicloginWithService

  • loginWithService(serviceName: string, params: any, infos: ConnectionInformations): Promise<LoginResult>

  • Parameters

    • serviceName: string
    • params: any
    • infos: ConnectionInformations

    Returns Promise<LoginResult>

publicloginWithUser

  • loginWithUser(user: CustomUser, infos: ConnectionInformations): Promise<LoginResult>
  • @description

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


    Parameters

    • user: CustomUser

      The user object.

    • infos: ConnectionInformations

      User's connection informations.

    Returns Promise<LoginResult>

    • Session tokens and user object.

publiclogout

  • logout(accessToken: string): Promise<void>
  • @description

    Logout a user and invalidate his session.

    @throws

    Parameters

    • accessToken: string

      User access token.

    Returns Promise<void>

    • Return a promise.

publicon

  • on(eventName: string, callback: HookListener): () => void
  • 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

    • eventName: string
    • callback: HookListener

    Returns () => void

      • (): void
      • Returns void

publicprepareMail

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

    • to: string
    • token: string
    • user: CustomUser
    • pathFragment: string
    • emailTemplate: EmailTemplateType
    • from: string

    Returns any

publicrefreshTokens

  • refreshTokens(accessToken: string, refreshToken: string, infos: ConnectionInformations): Promise<LoginResult>
  • @description

    Refresh a user token.

    @throws

    Parameters

    • accessToken: string

      User access token.

    • refreshToken: string

      User refresh token.

    • infos: ConnectionInformations

      User connection informations.

    Returns Promise<LoginResult>

    • LoginResult.

publicresumeSession

  • resumeSession(accessToken: string): Promise<CustomUser>
  • @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

    Parameters

    • accessToken: string

      User JWT access token.

    Returns Promise<CustomUser>

    Return the user associated to the session.

publicsanitizeUser

  • sanitizeUser(user: CustomUser): CustomUser
  • Parameters

    • user: CustomUser

    Returns CustomUser