Auth.js manages session persistence by issuing a session cookie that embeds a JWT along with session data. In Catalyst, this session data includes the customer access token, which allows your app to authenticate shoppers without storing session data on the server.
In any request, the session cookie authenticates the customer with the Catalyst app, while a customer access token authenticates them with BigCommerce so that you can add customer-specific context to many GraphQL operations. BigCommerce uses the customer access token to associate the request with the authenticated shopper and return personalized customer data.
Here’s how the flow works in Catalyst:
Anonymous session: BigCommerce generates an anonymous session as soon as any shopper hits the storefront for the first time. Catalyst then updates this session with a customer access token when a shopper logs in.
Customer Access Token Issuance: BigCommerce automatically issues a customer access token upon successful login (via password or JWT).
Storage in Auth.js Session: The customer access token is automatically stored within the session managed by Auth.js. With Auth.js, the callbacks.jwt function ensures that this token is embedded within the JWT when the user logs in, while the callbacks.session function makes the token accessible in the session object.
Session Retrieval: When your app needs session data, it calls the auth() function, which retrieves the session object containing the customer access token.
Authentication Flow for when your app needs to interact with BigCommerce on behalf of the customer:
getSessionCustomerAccessToken utility function to help you do so.cache value to no-store so guest shoppers don’t receive customer-specific information. For a full example, see the Catalyst Client reference.The customer context derived from the customer access token supports a variety of built-in functionalities. These functionalities are tied to the authenticated customer’s session and allow for personalized and secure interactions with the BigCommerce API.