useUserSignins() is the headless session-list hook behind the active-sessions section in <ManageAccount />. It loads the current user’s sign-in records with SWR, exposes a way to sign out one of those records, and keeps a manual refetch path so the UI can refresh after a mutation.
Usage
The following example shows a basic usage of useUserSignins().
export default function ActiveSessions() { const { signins, loading, removeSignin } = useUserSignins(); async function endFirstSession() { if (!signins?.length) { return; } await removeSignin(signins[0].id); } return ( <div> <button onClick={endFirstSession} disabled={loading}> End first session </button> <p>Sessions: {signins?.length ?? 0}</p> </div> );}
Return value
The hook returns the following fields and methods.
Revalidates the sign-ins query and returns the latest list from SWR.
›
loading: boolean;
Whether the shared client or the sign-ins query is still loading.
How it works
This hook is centered on the current user’s sign-in records, not just the active session. That is why it is the right source for account-security screens that list every active browser session.
The hook is SWR-backed, so signins can be undefined on the first render while the query is still resolving.
Calling removeSignin() does not automatically refetch the list inside the hook. The stock active-sessions UI explicitly calls both refetch() and the session refetch from useSession() after a sign-out action.
useSession() and useUserSignins() overlap, but they are aimed at different UI problems: useSession() manages the active session, while useUserSignins() manages the list of sign-ins attached to the current user.
When to use it
Examples
Render the active sign-in count
export default function SessionCount() { const { signins, loading } = useUserSignins(); if (loading) { return <p>Loading sessions…</p>; } return <p>{signins?.length ?? 0} active sessions</p>;}
Sign out one session and refresh the list
export default function EndFirstSession() { const { signins, removeSignin, refetch } = useUserSignins(); async function signOutFirst() { if (!signins?.length) { return; } await removeSignin(signins[0].id); await refetch(); } return <button onClick={signOutFirst}>End first session</button>;}