mirror of
https://github.com/PR0M3TH3AN/bitlogin.git
synced 2026-10-29 17:41:22 +00:00
Hosts had no method-agnostic session check: isActiveSigner() answers who backs window.nostr, which is deliberately false during a NIP-07 session (the extension IS the signer and rightly owns the slot) even though the user signed in through BitLogin. Sites using it as a login check mis-read extension sessions. A page-level registry (globalSession.ts, public data only -- method, pubkey, npub) is written at the single dispatchLogin point and cleared on logout and DOM removal, owner-scoped so one element's teardown can't clear another's session. window.bitlogin gains activeMethod() and activeSession(); the integration guide and llms.txt now spell out the two-questions distinction and lead with the one-login-surface pattern. Co-Authored-By: Claude Fable 5 <[email protected]>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
/** Page-level record of the widget session, backing window.bitlogin.activeMethod()
|
|
* and activeSession() (docs/login-methods.md §LM3).
|
|
*
|
|
* window.nostr ownership (isActiveSigner) and session state are DIFFERENT
|
|
* questions with different answers: during a NIP-07 session the extension owns
|
|
* the slot -- correctly -- yet the user very much signed in through BitLogin.
|
|
* Hosts that used isActiveSigner() as a session check got `false` there. This
|
|
* registry answers the session question directly, for every method.
|
|
*
|
|
* Public data only (method, public key, npub); never key material. Owner-scoped
|
|
* so one element's teardown cannot clear a session another element established.
|
|
*/
|
|
import type { SignerMethod } from "./signers/types.js";
|
|
|
|
export interface ActiveSessionInfo {
|
|
method: SignerMethod;
|
|
publicKey: string;
|
|
npub: string;
|
|
}
|
|
|
|
let current: { owner: object; info: ActiveSessionInfo } | null = null;
|
|
|
|
export function setActiveSession(owner: object, info: ActiveSessionInfo): void {
|
|
current = { owner, info };
|
|
}
|
|
|
|
export function clearActiveSession(owner: object): void {
|
|
if (current?.owner === owner) current = null;
|
|
}
|
|
|
|
export function getActiveSession(): ActiveSessionInfo | null {
|
|
return current ? { ...current.info } : null;
|
|
}
|