refactor(frontend): one account per browser, its local state under plain keys
The per-tab account pin, the X-Siftlode-Account header and ?account= go: the session cookie alone says who is asking. localStorage keys lose their account suffix; the browser records whose state it holds (siftlode.owner), BootGate hands it to the account the server answered as, and a different account starts from a clean slate (the public /watch keys stay). The first boot moves the account's old per-account copies onto the plain keys and drops other accounts' copies. Until the claim, and after another tab claimed the browser for someone else, the account helpers read and write nothing. The account panel lists no other accounts: "Add another account" becomes "Sign in as someone else" (Google's account chooser; the pick replaces this account, a cancel keeps it), shown where Google sign-in is configured.
This commit is contained in:
@@ -49,14 +49,6 @@ export function displayName(a: { display_name: string | null; email: string }):
|
||||
return a.display_name ?? a.email.split("@")[0]!;
|
||||
}
|
||||
|
||||
export interface Account {
|
||||
id: number;
|
||||
email: string;
|
||||
display_name: string | null;
|
||||
avatar_url: string | null;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
app_version: string;
|
||||
git_sha: string;
|
||||
@@ -73,14 +65,9 @@ export const accountApi = {
|
||||
const r = await req<{ authenticated: boolean } & Partial<Me>>("/api/me");
|
||||
return r.authenticated ? (r as Me) : null;
|
||||
},
|
||||
accounts: (): Promise<Account[]> => req("/api/me/accounts"),
|
||||
deleteAccount: (): Promise<{ deleted: boolean }> => req("/api/me/account", { method: "DELETE" }),
|
||||
switchAccount: (userId: number): Promise<{ ok: boolean; user_id: number }> =>
|
||||
req("/api/me/switch", { method: "POST", body: JSON.stringify({ user_id: userId }) }),
|
||||
// Signs the current tab's active account out of the browser wallet (per-tab aware via the
|
||||
// X-Siftlode-Account header that req() attaches).
|
||||
logout: (): Promise<{ ok: boolean; switched: boolean }> =>
|
||||
req("/auth/logout", { method: "POST" }),
|
||||
// Ends this browser's session.
|
||||
logout: (): Promise<{ ok: boolean }> => req("/auth/logout", { method: "POST" }),
|
||||
version: (): Promise<VersionInfo> => req("/api/version"),
|
||||
// Overwriting preferences is idempotent, so let it retry on a transient gateway blip.
|
||||
savePrefs: (p: Record<string, unknown>) =>
|
||||
|
||||
Reference in New Issue
Block a user