Skip to main content

MongoSessions

Implements

  • unknown

Index

Constructors

constructor

Methods

publiccreateSession

  • createSession(userId: string, token: string, connection?: ConnectionInformations, extraData?: object): Promise<string>
  • Create a new session attached to a user.


    Parameters

    • userId: string

      User id of the session.

    • token: string

      Random token used to identify the session.

    • connection: ConnectionInformations = {}

      Connection informations related to the session (such as user agent, ip etc..).

    • optionalextraData: object

      Any extra data you would like to add. The data will be added to the root of the object.

    Returns Promise<string>

publicfindSessionById

  • findSessionById(sessionId: string): Promise<any>
  • Get a session by his id.


    Parameters

    • sessionId: string

      Id used to query the session.

    Returns Promise<any>

publicfindSessionByToken

  • findSessionByToken(token: string): Promise<any>
  • Get a session by his token.


    Parameters

    • token: string

      Token used to query the session.

    Returns Promise<any>

publicinvalidateAllSessions

  • invalidateAllSessions(userId: string, excludedSessionIds?: string[]): Promise<void>
  • Invalidate all the session of a user.


    Parameters

    • userId: string

      User id of the sessions.

    • optionalexcludedSessionIds: string[]

      Can be used to whitelist some sessions. Eg: close all the sessions except these ones.

    Returns Promise<void>

publicinvalidateSession

  • invalidateSession(sessionId: string): Promise<void>
  • Invalidate a session.


    Parameters

    • sessionId: string

      Id of the session to invalidate.

    Returns Promise<void>

publicsetupIndexes

  • setupIndexes(options?: Omit<CreateIndexesOptions, unique | sparse>): Promise<void>
  • Setup the mongo indexes needed for the sessions.


    Parameters

    • options: Omit<CreateIndexesOptions, unique | sparse> = {}

      Options passed to the mongo native createIndex method.

    Returns Promise<void>

publicupdateSession

  • updateSession(sessionId: string, connection: ConnectionInformations, newToken?: string): Promise<void>
  • Update the session informations, token and connection informations.


    Parameters

    • sessionId: string

      Id used to update the session.

    • connection: ConnectionInformations

      Connection informations related to the session (such as user agent, ip etc..).

    • optionalnewToken: string

      New token that will replace the existing token for the session.

    Returns Promise<void>