Skip to content
Esc
navigateopen⌘Jpreview
Dashboard
On this page

Initial Setup

Enable email verification to ensure user authenticity and protect application routes.

Add required or optional email verification.

Overview

Email verification needs to be explicitly configured to work in your SuperTokens integration. The functionality offers two ways to set it up:

  • REQUIRED: The user needs to verify before they can access any protected routes.
  • OPTIONAL: The sessions include information about the email verification status, but it is up to you to enforce the requirement based on your business logic.

Before you start

For passwordless login, with email, a user’s email is automatically marked as verified when they login. Therefore, this flow only triggers if a user changes their email during a session.

Steps

1. Initialize the backend recipe

import SuperTokens from "supertokens-node";
import EmailVerification from "supertokens-node/recipe/emailverification";
import Session from "supertokens-node/recipe/session";

SuperTokens.init({
  appInfo: {
    apiDomain: "...",
    appName: "...",
    websiteDomain: "...",
  },
  recipeList: [
    EmailVerification.init({
      mode: "REQUIRED", // or "OPTIONAL"
    }),
    Session.init(),
  ],
});
import (
	"github.com/supertokens/supertokens-golang/recipe/emailverification"
	"github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels"
	"github.com/supertokens/supertokens-golang/recipe/session"
	"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
	"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
	supertokens.Init(supertokens.TypeInput{
		RecipeList: []supertokens.Recipe{
			emailverification.Init(evmodels.TypeInput{
				Mode: evmodels.ModeRequired, // or evmodels.ModeOptional
			}),
			session.Init(&sessmodels.TypeInput{}),
		},
	})
}
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import session
from supertokens_python.recipe import emailverification

init(
    app_info=InputAppInfo(
        api_domain="...", app_name="...", website_domain="..."),
    framework='...',  
    recipe_list=[
        emailverification.init(mode='REQUIRED'), # or 'OPTIONAL'
        session.init()
    ]
)

2. Initialize the frontend recipe

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, { SuperTokensWrapper } from "supertokens-auth-react";
import { getSuperTokensRoutesForReactRouterDom } from "supertokens-auth-react/ui";
import EmailVerification from "supertokens-auth-react/recipe/emailverification";
import { EmailVerificationPreBuiltUI } from "supertokens-auth-react/recipe/emailverification/prebuiltui";
import Session from "supertokens-auth-react/recipe/session";
import reactRouterDOM, { Routes, BrowserRouter as Router, Route } from "react-router-dom";

SuperTokens.init({
  appInfo: {
    apiDomain: "...",
    appName: "...",
    websiteDomain: "...",
  },
  recipeList: [
    EmailVerification.init({
      mode: "REQUIRED", // or "OPTIONAL"
    }),
    Session.init(),
  ],
});

function App() {
  return (
    <SuperTokensWrapper>
      <div className="App">
        <Router>
          <div className="fill">
            <Routes>
              {getSuperTokensRoutesForReactRouterDom(reactRouterDOM, [
                /* Other pre-built UI */ EmailVerificationPreBuiltUI,
              ])}
              // ... other routes
            </Routes>
          </div>
        </Router>
      </div>
    </SuperTokensWrapper>
  );
}
import SuperTokens, { SuperTokensWrapper } from "supertokens-auth-react";
import { canHandleRoute, getRoutingComponent } from "supertokens-auth-react/ui";
import EmailVerification from "supertokens-auth-react/recipe/emailverification";
import { EmailVerificationPreBuiltUI } from "supertokens-auth-react/recipe/emailverification/prebuiltui";
import Session from "supertokens-auth-react/recipe/session";

SuperTokens.init({
  appInfo: {
    apiDomain: "...",
    appName: "...",
    websiteDomain: "...",
  },
  recipeList: [
    EmailVerification.init({
      mode: "REQUIRED", // or "OPTIONAL"
    }),
    Session.init(),
  ],
});

function App() {
  if (canHandleRoute([/* Other pre-built UI */ EmailVerificationPreBuiltUI])) {
    return getRoutingComponent([/* Other pre-built UI */ EmailVerificationPreBuiltUI]);
  }
  return <SuperTokensWrapper>{/*Your app*/}</SuperTokensWrapper>;
}
// this goes in the auth route config of your frontend app (once the pre-built UI script has been loaded)

supertokensUIInit("supertokensui", {
  appInfo: {
    apiDomain: "...",
    appName: "...",
    websiteDomain: "...",
  },
  recipeList: [
    supertokensUIEmailVerification.init({
      mode: "REQUIRED", // or "OPTIONAL"
    }),
  ],
});

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

References

Verification email

This is how the email that the user receives looks like:

UI of the verification email sent to the registered user

You can find the source code of this template on GitHub To understand more about how you can customize it, check the email delivery section.

By default, the email verification link’s lifetime is 1 day. This can change via the Core configuration (time in milliseconds):

  • Go to the SuperTokens SaaS dashboard and select the relevant Managed deployment.
    • Open Configuration and find the Email Verification configuration card.
    • Change the email_verification_token_lifetime value. Configuration changes are saved automatically.
# Here we set the lifetime to 2 hours.

docker run \
    -p 3567:3567 \
    -e EMAIL_VERIFICATION_TOKEN_LIFETIME=7200000 \
    -d supertokens/supertokens-<db_name>
# You need to add the following to the config.yaml file.
# The file path can be found by running the "supertokens --help" command

email_verification_token_lifetime: 7200000

Next steps

API reference

API schema and response details