This class is used to handle shopper authentication. It is responsible for initializing shopper session, manage access and refresh tokens on server/browser environments. As well as providing a mechanism to queue network calls before having a valid access token.

Internal

Hierarchy

  • Auth

Accessors

Constructors

Methods

  • Make a post request to the OCAPI /session endpoint to bridge the session.

    The HTTP response contains a set-cookie header which sets the dwsid session cookie. This cookie is used on SFRA, and it allows shoppers to navigate between SFRA and this PWA site seamlessly; this is often used to enable hybrid deployment.

    (Note: this method is client side only, b/c MRT doesn't support set-cookie header right now)

    Returns Promise<Response>

  • This method stores the TokenResponse object retrived from SLAS, and store the data in storage.

    Parameters

    Returns void

  • Used to validate JWT token expiration.

    Parameters

    • token: string

    Returns boolean

  • A wrapper method for commerce-sdk-isomorphic helper: loginRegisteredUserB2C.

    Parameters

    • credentials: {
          password: string;
          username: string;
      }
      • password: string
      • username: string

    Returns Promise<TokenResponse>

  • Decode SLAS JWT and extract information such as customer id, usid, etc.

    Parameters

    • jwt: string

    Returns {
        customerId: string;
        isGuest: boolean;
        usid: string;
    }

    • customerId: string
    • isGuest: boolean
    • usid: string
  • The ready function returns a promise that resolves with valid ShopperLogin token response.

    When this method is called for the very first time, it initializes the session by following the public client auth flow to get access token for the user. The flow:

    1. If we have valid access token - use it
    2. If we have valid refresh token - refresh token flow
    3. PKCE flow

    Returns Promise<TokenResponse>

  • Creates a function that only executes after a session is initialized.

    Type Parameters

    • Args extends unknown[]

    • Data

    Parameters

    • fn: ((...args) => Promise<Data>)

      Function that needs to wait until the session is initialized.

        • (...args): Promise<Data>
        • Parameters

          • Rest ...args: Args

          Returns Promise<Data>

    Returns ((...args) => Promise<Data>)

    Wrapped function

      • (...args): Promise<Data>
      • Creates a function that only executes after a session is initialized.

        Parameters

        • Rest ...args: Args

        Returns Promise<Data>

        Wrapped function

Properties

OCAPISessionsURL: string
REFRESH_TOKEN_EXPIRATION_DAYS: number = 90
fetchedToken: string
pendingToken: undefined | Promise<TokenResponse>
redirectURI: string
shopperCustomersClient: ShopperCustomers<ApiClientConfigParams>