Menu
Guides
Storefront Development

Storefront Development

Enabling refresh token on FastStore

Automatically refresh user sessions without re-logging in by enabling the refresh token flow in your FastStore project.

2 min read
Refresh token is a security mechanism that allows users to obtain a new, short-lived access token without requiring them to log in again.
The FastStore SDK Session includes built-in support for the refresh token flow. It automatically manages token renewal, session management, and error handling. As a FastStore user, you only need to enable the refresh token in your project configuration. The SDK will manage the process automatically, without requiring you to implement a custom flow.
In this guide, you'll learn how to enable the refresh token in a FastStore store.
For details about how the refresh tokens work, check the Refresh token flow for headless implementations guide.

Before you begin

Update your FastStore project

Make sure your project is updated to the latest version. To do so, follow these steps:
  1. Open your project in a code editor.
  2. Open a terminal and run the following command to update the FastStore packages to the latest version:

_10
yarn upgrade -L --scope @faststore

Enable persistent login

In the VTEX Admin, enable persistent login and set the refresh token expiration time (from 1 to 365 days):
  1. Go to Account settings > Authentication.
  2. On the Webstore tab, find the Persistent login card and click the toggle to enable it.
  3. To change the duration, click Edit, enter a number of days from 1 to 365 in the Session duration field, and click Save.
For more details, see Configuring persistent login for customers. Without persistent login enabled in your account, you won’t be able to enable the refresh token in your project.

Instructions

  1. Open your FastStore project in a code editor.
  2. In the discovery.config.js file, under the experimental section, add the refreshToken flag and set its value to true:
    discovery.config.js

    _10
    experimental: {
    _10
    …
    _10
    refreshToken: true
    _10
    }

  3. Commit and push your changes to the main branch to deploy the changes to production.