SuperTokens

SuperTokens

  • Docs
  • Discord
  • Blog

›Multi Tenancy

SIDEBAR_REPLACE_DOC_Introduction

  • Introduction

Quick setup

  • Video tutorial & Architecture
  • Frontend
  • Backend
  • Core

    • Core Overview
    • Self Hosted setup with Docker
    • Self Hosted setup without Docker
    • Managed Service

    Database Setup

    • MySQL
    • PostgreSQL

Common customizations

  • Sign Out
  • Sign Up Form

    • About
    • Adding Extra Fields
    • Adding / Modifying field validators
    • Embed in a page
    • Handling signup success
    • Terms of service & Privacy policy links

    Sign In Form

    • About
    • Adding / Modifying field validators
    • Password managers
    • Embed in a page
    • Show Sign In by default

    Reset Password

    • About
    • Reset password email
    • Embed in a page

    Email Verification

    • About
    • Customising the email sent
    • Embed in a page

    Sessions

    • About
    • Cookie Consent
    • Creating a new session
    • Session Verification in API
    • Change session timeout
    • Checking if a session exists on the frontend
    • Get user information on the frontend
    • Using with FaunaDB

    Styling

    • Changing Colours
    • Changing Style via CSS
    • Themes

    Changing base path

    • Website Base Path
    • API Base Path

    Multi Tenancy

    • About
    • One login, many sub domains
    • One login per sub domain
  • User Pagination

Advanced users

    Advanced session management

    • Share sessions across sub domains
    • Anti CSRF
    • JWT Signing key rotation
    • Access token blacklisting
    • Customizing Error Handling

    Supertokens Core config

    • Adding API Keys
    • Tuning Performance
    • Logging
    • Rename database tables

    Make your own frontend

    • Sign-up / Sign-in custom theme
    • Reset password custom theme

    Make your own backend

    • Sign up custom API
    • Sign in custom API
    • Reset password custom APIs

NextJS

  • SuperTokens with NextJS
  • Deploy with Vercel
  • Deploy with Netlify

SIDEBAR_REPLACE_DOC_SDKs

  • SDKs

SIDEBAR_REPLACE_DOC_Compatibility Table

  • Compatibility Table

Migration

  • Migrating from an older version of SuperTokens
  • Migrating to SuperTokens
  • Migrating away from SuperTokens
  • From managed service to self hosted

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 use abc.example.com.
  • Customer 2: Let's say that the name of the customer is xyz. In this case, we want them to use xyz.example.com.

Frontend setup:

  • Change the init function params
    SuperTokens.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 frontend
    supertokens.init({
        appInfo: {
            appName: "YOUR APP NAME",
            apiDomain: "YOUR API DOMAIN",
            websiteDomain: "auth.example.com",
            websiteBasePath: "/"
    
        },
        recipeList: [...]
    });
    
← AboutOne login per sub domain →