One login, many sub domains
We will demonstrate the changes required for this with an example:
- Login domain:
auth.example.com
. - Customer 1: Let's say that the name of the customer is
abc
. In this case, we want them to useabc.example.com
. - Customer 2: Let's say that the name of the customer is
xyz
. In this case, we want them to usexyz.example.com
.
Frontend setup:
- Change the
init
function paramsSuperTokens.init({ appInfo: { appName: "YOUR APP NAME", apiDomain: "YOUR API DOMAIN", websiteDomain: "auth.example.com", websiteBasePath: "/" }, recipeList: [ EmailPassword.init( getRedirectionURL: async (context) => { if (context.action === "SUCCESS") { const userId = Session.getUserId(); // getUserDomain is your implementation let userDomain = await getUserDomain(userId); return `${userDomain}.example.com`; } } ), Session.init({ sessionScope: ".example.com" }) ] });
With the above, we are setting the login screen on auth.example.com
. We are also allowing a session to work on any subdomain of example.com
.
Backend setup:
- Change the
init
function params in accordance with the frontendsupertokens.init({ appInfo: { appName: "YOUR APP NAME", apiDomain: "YOUR API DOMAIN", websiteDomain: "auth.example.com", websiteBasePath: "/" }, recipeList: [...] });