Skip to main content

Updating roles in a session

This can only be done on the backend by using the updateAccessTokenPayload function post session verification:

import express from "express";import { verifySession } from "supertokens-node/recipe/session/framework/express";import { SessionRequest } from "supertokens-node/framework/express";
let app = express();
app.post("/update-role", verifySession(), async (req: SessionRequest, res) => {
    let userId = req.session!.getUserId();
    let role = "newRole"; // TODO: fetch based on user
    // Note that this will override any existing access token payload    // that you may have provided earlier.    await req.session!.updateAccessTokenPayload(        { role }    );
    //....});