import { Schema, TokenResult } from '@plitzi/sdk-shared'; export type StorageKind = Exclude; export type StoredSession = { version: number; token?: TokenResult; user?: U; /** * Unix seconds of the last time the backend answered about this session — including the answer that nobody is * signed in. Storing the negative answer is what stops a signed-out visitor from paying for a request on every * single page load just to be told the same thing again. */ validatedAt: number; }; /** * Where a session survives a reload. It holds the user next to the token on purpose: a token alone says a session is * live but not whose it is, so a page that stored only the token had to ask the backend who it was talking to before * it could render anything — which is the reason boot used to cost a round trip. */ declare class SessionStore { private readonly kind; private readonly key; constructor(kind: StorageKind, key: string); private get area(); read(): StoredSession | undefined; write(session: Omit, 'version'>): void; clear(): void; /** * Fires when another tab writes the session. Signing out in one tab has to end it in all of them, and a renewal in * one has to be adopted by the rest — two tabs that each renew on their own would rotate the refresh token out from * under each other, and whichever lost the race would sign its user out for no reason. */ subscribe(listener: (session?: StoredSession) => void): () => void; } export default SessionStore;