Skip to content
Torii docs

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.

  • 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>
);
}
NameTypeDescription
sessionsSession[]Active sessions. Empty while loading or when signed out. Each carries id, userId, environmentId, userAgent, ipAddress, createdAt, expiresAt, lastUsedAt.
isLoadingbooleantrue while the session list is being fetched.
errorToriiError | nullThe 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.
revokingIdstring | nullId of the session currently being revoked via revokeSession, else null.
revokingAllbooleantrue while a revokeAllOtherSessions call is in progress.
import type { UseSessionsReturn, Session } from '@torii-js/torii-react';