useUserSignins() hook

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.

signins: SignIn[] | undefined;
Sign-in records attached to the current user.
[].id?: string | undefined;
Sign-in identifier.
[].user_id?: string | undefined;
User identifier attached to the sign-in.
[].active_organization_membership_id?: string | undefined;
Active organization membership for the sign-in.
[].active_workspace_membership_id?: string | undefined;
Active workspace membership for the sign-in.
[].expiresAt?: string | undefined;
Sign-in expiry timestamp.
[].lastActiveAt?: string | undefined;
Last activity timestamp for the sign-in.
[].ipAddress?: string | undefined;
IP address recorded for the sign-in.
[].browser?: string | undefined;
Browser recorded for the sign-in.
[].device?: string | undefined;
Device recorded for the sign-in.
[].city?: string | undefined;
City recorded for the sign-in.
[].region?: string | undefined;
Region recorded for the sign-in.
[].regionCode?: string | undefined;
Region code recorded for the sign-in.
[].country?: string | undefined;
Country recorded for the sign-in.
[].countryCode?: string | undefined;
Country code recorded for the sign-in.
[].user?: CurrentUser | undefined;
User record attached to the sign-in.
id?: string | undefined;
Current user identifier.
first_name?: string | undefined;
User first name.
last_name?: string | undefined;
User last name.
username?: string | undefined;
Username when one is set.
error: Error | null;
SWR error for the current sign-ins query.
removeSignin: (id: string) => Promise<ApiResult<unknown>>;
Signs out one specific sign-in record.
refetch: () => Promise<SignIn[] | undefined>;
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>;}

    On this page