Skip to main content

Creating a new session

How to create a new session#

Create a new session after verifying user's credentials in the login API, or after creating a new user in the sign up API.

import express from "express";
import Session from "supertokens-node/recipe/session";

let app = express();

app.post("/login", async (req, res) => {

// verify user's credentials...

let userId = "userId"; // get from db

await Session.createNewSession(req, res, userId);

/* a new session has been created.
* - an access & refresh token has been attached to the response's cookie
* - a new row has been inserted into the database for this new session
*/

res.json({ message: "User logged in!" });
})
Which UI do you use?
Custom UI
Pre built UI