feat: implement ActiveSessions component and JWT session tracking to manage user device access

This commit is contained in:
estifanos
2026-08-19 11:00:20 +00:00
parent ff89b9af5e
commit ec28f6456d
12 changed files with 518 additions and 11 deletions

View File

@@ -0,0 +1,18 @@
/**
* Session id from the access token, when it carries one.
*
* `/sessions/my-sessions` returns no "this is you" flag, so the only way to
* stop the user revoking the session they are sitting in is to read the id off
* the token. Undefined is a normal answer — an opaque token just means no
* "This device" badge and a confirm dialog that warns instead.
*/
export function currentSessionId(token?: string): string | undefined {
const payload = token?.split('.')[1];
if (!payload) return undefined;
try {
const claims = JSON.parse(atob(payload.replace(/-/g, '+').replace(/_/g, '/')));
return claims.sessionId ?? claims.sid ?? claims.jti;
} catch {
return undefined;
}
}