Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JwtApi<Credentials, AuthResponse, UserId> Abstract

Provides methods to interact with backend. Errors, thrown by the methods, MUST be human-readable strings. You can implement this using ngx-custmapp-errors package (if you want, also use ngx-customapp-proto-http). You could also learn more about error handling convention by reading the ngx-customapp-errors docs.

Type Parameters

  • Credentials

  • AuthResponse

  • UserId = number

Hierarchy

  • JwtApi

Index

Constructors

  • new JwtApi<Credentials, AuthResponse, UserId>(): JwtApi<Credentials, AuthResponse, UserId>
  • Type Parameters

    • Credentials

    • AuthResponse

    • UserId = number

    Returns JwtApi<Credentials, AuthResponse, UserId>

Properties

login: ((credentials: Credentials) => Observable<AuthResponse>)

Type declaration

    • (credentials: Credentials): Observable<AuthResponse>
    • Should make an auth request to the server. Usually supports logging in by a password or by a JWT.

      Parameters

      • credentials: Credentials

        Login and password or something else, depending on the target application

      Returns Observable<AuthResponse>

      Usually returns information about the user and JWT tokens. JWT is retrieved from auth response with JwtConfig.authResponseToJwt.

loginAs?: ((masterAccessToken: JwtInfo, userId: UserId) => Observable<AuthResponse>)

Type declaration

    • (masterAccessToken: JwtInfo, userId: UserId): Observable<AuthResponse>
    • Used to implement feature, which allows logging in as another user. For example, director role may want to log in as manager role. This feature is optional.

      Parameters

      • masterAccessToken: JwtInfo

        the access token of the current user (not target).

      • userId: UserId

        the parameter used to build the request. Might be complex and include user role, location, etc.

      Returns Observable<AuthResponse>

      The AuthResponse as if the target user logged in using his credentials.

logout: ((accessToken: JwtInfo, fromAllDevices?: boolean) => Observable<void>)

Type declaration

    • (accessToken: JwtInfo, fromAllDevices?: boolean): Observable<void>
    • Invalidates tokens.

      Parameters

      • accessToken: JwtInfo

        the access token of the user being logged out. Might be the token, returned by loginAs function.

      • Optional fromAllDevices: boolean

        Optional functionality

      Returns Observable<void>

refresh: ((refreshToken: JwtInfo) => Observable<JwtGroup<JwtInfo>>)

Type declaration

    • Uses valid long-living refresh token to get new access and refresh tokens from backend. Returned observable should error when

      Parameters

      Returns Observable<JwtGroup<JwtInfo>>

Generated using TypeDoc