Skip to main content

5a. Session verification in an API call


This is applicable for when the frontend calls an API in the /pages/api folder.

For this guide, we will assume that we want an API /api/user GET which returns the current session information.

1) Create a new file /pages/api/user.js#

  • An example of this is here.

2) Call the supertokens.init function#

Remember that whenever we want to use any functions from the supertokens-node lib, we have to call the supertokens.init function at the top of that serverless function file.

import supertokens from 'supertokens-node'import { backendConfig } from '../../../config/backendConfig'

3) Call the verifySession session function#

Please fill the form below to see the code snippet (* = Required)
Website Domain:*
Information about the question
This is the URL of your website.
Submit form