Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • getSession(token: string): Promise<Session | null>
  • Returns the {@link Session} linked to a {@link Session#token}.

    Parameters

    • token: string

      Token to fetch session for

    Returns Promise<Session | null>

    The {@link Session} associated with this token

  • getUserBySession(token: string): Promise<User | null>
  • Returns the {@link User} a {@link Session} belongs to based on its {@link Session#token}.

    Parameters

    • token: string

      Token to fetch user for

    Returns Promise<User | null>

    The {@link User} associated with the session of this token

  • initSession(user: User): Promise<Session>
  • Initialises a {@link Session} for a {@link User}.

    Parameters

    • user: User

      The {@link User} to initialise the session for

    Returns Promise<Session>

    The newly initialised {@link Session}

  • terminateSession(session: Session): Promise<void>
  • Invalidates a {@link Session}.

    Parameters

    • session: Session

      The {@link Session} to terminate

    Returns Promise<void>

  • validateSession(token: string, refresh?: boolean): Promise<{ isValid: boolean; newSession?: Session }>
  • Validates that a {@link Session#token}:

    • Is a valid JWT
    • Is an existing session
    • Belongs to the user encoded within it
    • Is not expired

    By supplying the refresh parameter, the session can be refreshed (i.e. a new token generated and the old one discarded) so the user does not ever have to re-login if they just keep logging in more often than the token lifetime.

    Parameters

    • token: string

      Token to validate

    • Optional refresh: boolean

      Whether to refresh the session

    Returns Promise<{ isValid: boolean; newSession?: Session }>

    Whether the session was valid, and if refresh is enabled, the new session to give to the user instead

Generated using TypeDoc