Skip to main content

Working with multiple API endpoints

To enable use of sessions for multiple API endpoints, you need to use the cookieDomain config on the frontend and backend Session.init function call.


All your API endpoints must have the same top level domain. For example, they can be {"", ""}, but they cannot be {"", ""}.

Step 1) Backend config#

You need to set the cookieDomain value to be the common top level domain. For example, if your API endpoints are {"", "", ""}, the common portion of these endpoints is "" (The dot is important). So you would need to set the following:

let SuperTokens = require("supertokens-node");let Session = require("supertokens-node/recipe/session");
SuperTokens.init({    supertokens: {...},    appInfo: {...},    recipeList: [        Session.init({            cookieDomain: "";         })    ]});

The above will set the session cookies' domain to, allowing them to be sent to *


The value of apiDomain in appInfo must point to an exact API domain only.

  • This should be the API in which you want to expose all the auth related endpoints (for example /auth/signin).
  • The frontend login widgets will talk to these APIs

Step 2) Frontend config#

You need to set the same value for cookieDomain on the frontend. This will allow the frontend SDK to apply interception and automatic refreshing across all your API calls:

import React from 'react';
import SuperTokens from "supertokens-auth-react";import Session from "supertokens-auth-react/recipe/session";
SuperTokens.init({    appInfo: {...},    recipeList: [        Session.init({            cookieDomain: ""         })    ]});