Skip to main content

Fetching sessions for a user

Given a user ID, we can fetch all sessions that are currently active for that user using the getAllSessionHandlesForUser function:

let Session = require("supertokens-node/recipe/session");
let userId = "someUserId" // fetch somehow
// sessionHandles is string[]let sessionHandles = await Session.getAllSessionHandlesForUser(userId);
sessionHandles.forEach((handle) => {
    /* we can do the following with the handle:     * - revoke this session     * - change access token payload or session data     * - fetch access token payload or session data    */})