Skip to main content

If you are using our backend SDK that is lesser than the following versions, please visit the older documentation link here.

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:

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

async function getSessions() {
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
*/
})
}
Multi Tenancy

By default, getAllSessionHandlesForUser will fetch all the sessionHandles for the user across all the tenants. If you want to fetch the sessions for a user in a specific tenant, you can pass the tenant ID as a parameter to the function call.

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI