Skip to main content

5a. Session verification in an API call

note

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.

pages/index.js
import supertokens from 'supertokens-node'import { backendConfig } from '../../../config/backendConfig'
supertokens.init(backendConfig())

3) Call the verifySession session function#

Please fill the form below to see the code snippet (* = Required)
Website Domain:*
This is the URL of your website, without any path.
Fill form to submit