useSessions
useSessions() lists the signed-in user’s active sessions and exposes helpers
to revoke a single session or every session except the current one. It tracks
loading state and per-action revoking flags so you can disable the right row
while a revoke is in flight.
Not the account switcher. This hook is the current user’s device list across browsers, for revoking sessions. To list the accounts signed in on this browser and switch between them (multi-session), use
useSessionList().
When to use it
Section titled “When to use it”- Build a “where you’re logged in” / active-devices screen with sign-out controls.
import { useSessions } from '@torii-js/torii-react';
function Sessions() { const { sessions, revokeSession, revokingId } = useSessions();
return ( <ul> {sessions.map((s) => ( <li key={s.id}> {s.userAgent ?? 'Unknown device'} <button disabled={revokingId === s.id} onClick={() => revokeSession(s.id)} > Revoke </button> </li> ))} </ul> );}Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
sessions |
Session[] |
Active sessions. Empty while loading or when signed out. Each carries id, userId, environmentId, userAgent, ipAddress, createdAt, expiresAt, lastUsedAt. |
isLoading |
boolean |
true while the session list is being fetched. |
error |
ToriiError | null |
The ToriiError from the last fetch or revoke, or null. Branch on error.code; localize from your own copy. |
refresh |
() => Promise<void> |
Re-fetch the session list from the server. |
revokeSession |
(sessionId: string) => Promise<MutationResult<void>> |
Revoke one session by id. Resolves a MutationResult; check .ok. |
revokeAllOtherSessions |
() => Promise<MutationResult<void>> |
Revoke every session except the current one. Resolves a MutationResult; check .ok. |
revokingId |
string | null |
Id of the session currently being revoked via revokeSession, else null. |
revokingAll |
boolean |
true while a revokeAllOtherSessions call is in progress. |
TypeScript
Section titled “TypeScript”import type { UseSessionsReturn, Session } from '@torii-js/torii-react';