Skip to main content

Backend Integration

Example#

An example implementation can be found here.

1) Install#

npm i -s supertokens-node

2) Initialise SuperTokens#

Please fill the form below to see the code snippet (* = Required)
Your app's name:*
Information about the question
This is the name of your application
API Domain:*
Information about the question
This is the URL of your app's API server.
API Base Path:
Information about the question
SuperTokens will expose it's APIs scoped by this base API path.
Website Domain:*
Information about the question
This is the URL of your website.
Website Base Path:
Information about the question
SuperTokens UI will be shown on this website route.
Submit form

3) Set up your delivery method#

important

We are working on our own SMS / email delivery service which will make this step much easier. Until then, you have to send the SMS / emails yourself.

The See next step comment above is a placeholder where you must provide a function that will send the user the information necessary to log in or sign up:

How do you want to identify your users?
Only phone numberOnly emailEmail or phone number

4) Add the SuperTokens APIs & CORS setup#

Please fill the form below to see the code snippet (* = Required)
API Base Path:
Information about the question
SuperTokens will expose it's APIs scoped by this base API path.
Website Domain:*
Information about the question
This is the URL of your website.
Submit form

5) Add the SuperTokens error handler#

Add the errorHandler AFTER all your routes, but BEFORE your error handler

import express from "express";import {errorHandler} from "supertokens-node/framework/express";
const app = express();// ...your API routes
// Add this AFTER all your routesapp.use(errorHandler())
// your own error handlerapp.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {    // TODO});

6) Test if sign up is setup correctly#

  • Visit the login form on the website.
  • Try to sign up.
  • If after signing up, you are redirected to /, everything is setup correctly 😁
  • If not, you can always ask for help via Github issues or via our Discord

7) Setup the SuperTokens core#

Are you using https://try.supertokens.com as the connection URI in the init function?
YesNo