Skip to main content

Reading roles from a session

You can read the roles assigned to a user in any API, to do this we use the userId post session verification to fetch all roles.

import express from "express";import { verifySession } from "supertokens-node/recipe/session/framework/express";import { SessionRequest } from "supertokens-node/framework/express";import UserRoles from "supertokens-node/recipe/userroles";
let app = express();"/update-blog", verifySession(), async (req: SessionRequest, res) => {
    let userId = req.session!.getUserId();    let roles = await UserRoles.getRolesForUser(userId)});