Skip to content
Esc
navigateopen⌘Jpreview
Dashboard
On this page

Share sessions across sub domains

Configure SuperTokens to share sessions across multiple subdomains.

Overview

Configure sharing sessions across multiple subdomains in SuperTokens by setting the sessionTokenFrontendDomain attribute of the Session recipe in your frontend code.

Steps

1. Update the frontend configuration

UI type

You need to make changes to the auth route configuration, as well as to the supertokens-web-js SDK configuration at the root of your application:

This change is in your auth route configuration.

import SuperTokens from "supertokens-auth-react";
import Session from "supertokens-auth-react/recipe/session";

SuperTokens.init({
  appInfo: {
    // ...
    // this should be equal to the domain where the user will see the login UI
    apiDomain: "...",
    appName: "...",
    websiteDomain: "https://example.com",
  },
  recipeList: [
    Session.init({
      sessionTokenFrontendDomain: ".example.com",
    }),
  ],
});
supertokensUIInit({
  appInfo: {
    // ...
    // this should be equal to the domain where the user will see the login UI
    apiDomain: "...",
    appName: "...",
    websiteDomain: "https://example.com",
  },
  recipeList: [
    supertokensUISession.init({
      sessionTokenFrontendDomain: ".example.com",
    }),
  ],
});

This change goes in the supertokens-web-js SDK configuration at the root of your application:


See also

API reference

API schema and response details