Skip to main content

1. Configuration

1) Install supertokens package#

yarn install supertokens-nodeyarn install supertokens-auth-reactyarn install nextjs-cors

2) Create a configuration file (config/supertokensConfig.js)#

  • Create a config folder in the root directory of your project
  • Create a supertokensConfig.js inside the config folder.
  • An example of this file can be found here.

3) Create a frontend config function#

This function will return the config object used to configure supertokens-auth-react:

  • Fill in your information in the appInfo object. To learn more about this config, please visit the appInfo page.
  • All configuration options can be found here

import EmailPasswordReact, {Google, Facebook} from 'supertokens-auth-react/recipe/emailpassword'import SessionReact from 'supertokens-auth-react/recipe/session'
const appInfo = {  // learn more about this on https://supertokens.io/docs/emailpassword/appinfo  appName: 'SuperTokens Demo App', // TODO: Your app name  websiteDomain: "http://localhost:3000", // TODO: Add your website domain  apiDomain: "http://localhost:3000", // TODO: should be equal to `websiteDomain` in case using the `api` folder for APIs  apiBasePath: "/api/auth/", // /api/auth/* will be where APIs like sign out, sign in will be exposed}
export const frontendConfig = () => {  return {    appInfo,    recipeList: [      EmailPasswordReact.init(),      SessionReact.init(),    ],  }}

4) Create a backend config function#

This function will return the config object used to configure supertokens-node:

  • Add secrets for your third party login providers
  • All configuration options can be found here

import EmailPasswordNode, {Google, Facebook} from 'supertokens-node/recipe/emailpassword'import SessionNode from 'supertokens-node/recipe/session'
export const backendConfig = () => {  return {    supertokens: {      connectionURI: 'https://try.supertokens.io',    },    appInfo,    recipeList: [      EmailPasswordNode.init(),      SessionNode.init(),    ],    isInServerlessEnv: true,  }}

5) Call the init functions#

  • Create a /pages/_app.js file. You can learn more about this file here.
  • An example of this can be found here