Skip to main content

3. Adding auth APIs

We will add all the backend APIs for auth on /api/auth. This can be changed by setting the apiBasePath property in the appInfo object in the supertokensConfig.js file. For the rest of this page, we will assume you are using /api/auth.

1) Create the pages/api/auth/[[...path]].js page#

  • Be sure to create the auth folder in the pages/api/ folder.
  • [[...path]].js will use the middleware exposed by supertokens-node which exposes all the APIs like sign in, sign up etc..
  • An example of this can be found here.

2) Add the supertokens middleware:#

important

Notice that we called supertokens.init above. This is because this is run in a serverless function and before using any supertokens-node function, we must call the supertokens.init function.

3) Use the login widget#

If you are now able to sign in or sign up, this means the backend setup is done correctly! If not, please feel free to ask questions on Discord