Private
dataA wrapper method for commerce-sdk-isomorphic helper: authorizeIDP. Initiates OAuth2 authorization flow for Identity Provider (IDP) login.
A wrapper method for commerce-sdk-isomorphic helper: authorizePasswordless.
Trusted agent authorization
Optional
loginThis method is not supported on the server, it is a client-only method.
Private
clearECOMSessionFor Hybrid storefronts ONLY!!! This method clears the dwsid cookie from the browser. In a hybrid setup, dwsid points to an ECOM session and is passed between PWA Kit and SFRA/SG sites via "dwsid" cookie.
Whenever a registered shopper logs in on PWA Kit, we must clear the dwsid cookie if one exists. When shopper navigates to SFRA as a logged-in shopper, ECOM notices a missing DWSID, generates a new DWSID and triggers the onSession hook which uses registered shopper refresh-token and restores session and basket on SFRA.
Private
clearSFRAAuthFor Hybrid storefronts ONLY!!! This method clears out SLAS access token generated in Plugin SLAS and passed in via "cc-at" cookie.
In a hybrid setup, whenever any SLAS flow executes in Plugin SLAS and an access token is generated, the access token is sent over to PWA Kit using cc-at cookie.
PWA Kit will check to see if cc-at cookie exists, if it does, the access token value in localStorage is updated with value from the cc-at cookie and is then used for all SCAPI requests made from PWA Kit. The cc-at cookie is then cleared.
Private
clearPrivate
convertConverts a duration in seconds to a Date object. This function takes a number representing seconds and returns a Date object for the current time plus the given duration.
The number of seconds to add to the current time.
A Date object for the expiration time.
Private
deleteThis method extracts the status and message from a ResponseError that is returned by commerce-sdk-isomorphic.
commerce-sdk-isomorphic throws a ResponseError
, but doesn't export the class.
We can't use instanceof
, so instead we just check for the response
property
and assume it is a ResponseError
if a response is present
Once commerce-sdk-isomorphic exports ResponseError
we can revisit if this method is
still required.
contained within the ResponseError
error if the error is not a ResponseError
Private
getReturns the SLAS access token or an empty string if the access token is not found in local store or if SFRA wants PWA to trigger refresh token login.
On PWA-only sites, this returns the access token from local storage. On Hybrid sites, this checks whether SFRA has sent an auth token via cookies. Returns an access token from SFRA if it exist. If not, the access token from local store is returned.
This is only used within this Auth module since other modules consider the access token from this.get('access_token') to be the source of truth.
access token
Return the value of the DNT cookie or undefined if it is not set. The DNT cookie being undefined means that there is a necessity to get the user's input for consent tracking, but not that there is no DNT value to apply to analytics layers. DNT value will default to a certain value and this is reflected by effectiveDnt.
If the cookie value is invalid, then it will be deleted in this function.
If includeDefaults is true, then even if the cookie is not defined, defaultDnt will be returned, if it exists. If defaultDnt is not defined, then the SDK Default will return (false)
Optional
options: DntOptionsA wrapper method for commerce-sdk-isomorphic helper: getPasswordLessAccessToken.
A wrapper method for the SLAS endpoint: getPasswordResetToken.
Private
getRetrieves our refresh token cookie ttl value from the following sources in order:
Private
handleThis method stores the TokenResponse object retrieved from SLAS, and store the data in storage.
Private
isA wrapper method for commerce-sdk-isomorphic helper: loginGuestUser.
Optional
parameters: CustomQueryParametersA wrapper method for commerce-sdk-isomorphic helper: loginIDPUser.
A wrapper method for commerce-sdk-isomorphic helper: loginRegisteredUserB2C.
This method uses a body-based API similar to the register function for consistency. Supports custom parameters through the customParameters field.
Trusted agent login
Optional
clientOptional
codeOptional
loginOptional
state?: stringOptional
usid?: stringThis method is not supported on the server, it is a client-only method.
A wrapper method for commerce-sdk-isomorphic helper: logout.
Decode SLAS JWT and extract information such as customer id, usid, etc.
This method queues the requests and handles the SLAS token response.
It returns the queue.
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:
This is a wrapper method for ShopperCustomer API registerCustomer endpoint.
Trusted agent refresh handler
Optional
loginId: stringOptional
usid: stringOptional
refresh: booleanThis method is not supported on the server, it is a client-only method.
A wrapper method for the SLAS endpoint: resetPassword.
Private
setOptional
options: unknownCreates a function that only executes after a session is initialized.
Function that needs to wait until the session is initialized.
Rest
...args: ArgsWrapped function
Creates a function that only executes after a session is initialized.
Rest
...args: ArgsWrapped function
Private
clientPrivate
clientPrivate
defaultPrivate
fetchedPrivate
hybridPrivate
isPrivate
loggerPrivate
passwordlessPrivate
pendingPrivate
redirectURIPrivate
refreshPrivate
refreshPrivate
refreshPrivate
shopperPrivate
silencePrivate
stores
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