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:
@@ -5,11 +5,10 @@
|
||||
// (sessionStorage): it survives a reload and a trip to another page, and a new tab starts on the first.
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { act, renderHook } from "@testing-library/react";
|
||||
import { ACTIVE_ACCOUNT_KEY } from "./activeAccount";
|
||||
import { setTabRaw, useTabPersistedState } from "./storage";
|
||||
import { claimLocalData, setTabRaw, useTabPersistedState } from "./storage";
|
||||
|
||||
beforeEach(() => {
|
||||
sessionStorage.setItem(ACTIVE_ACCOUNT_KEY, "1");
|
||||
claimLocalData(1);
|
||||
});
|
||||
afterEach(() => {
|
||||
sessionStorage.clear();
|
||||
@@ -21,8 +20,8 @@ describe("a page's sub-tab, per browser tab", () => {
|
||||
const first = renderHook(() => useTabPersistedState("siftlode.configTab", "access"));
|
||||
expect(first.result.current[0]).toBe("access");
|
||||
act(() => first.result.current[1]("plex"));
|
||||
expect(sessionStorage.getItem("siftlode.configTab.1")).toBe("plex");
|
||||
expect(localStorage.getItem("siftlode.configTab.1")).toBeNull();
|
||||
expect(sessionStorage.getItem("siftlode.configTab")).toBe("plex");
|
||||
expect(localStorage.getItem("siftlode.configTab")).toBeNull();
|
||||
// The page mounts again in this tab (a reload, or back from another page): it is where it was.
|
||||
first.unmount();
|
||||
expect(
|
||||
@@ -31,10 +30,10 @@ describe("a page's sub-tab, per browser tab", () => {
|
||||
});
|
||||
|
||||
it("ignores a position left in localStorage by an older build, and clears it", () => {
|
||||
localStorage.setItem("siftlode.configTab.1", "plex");
|
||||
localStorage.setItem("siftlode.configTab", "plex");
|
||||
const { result } = renderHook(() => useTabPersistedState("siftlode.configTab", "access"));
|
||||
expect(result.current[0]).toBe("access");
|
||||
expect(localStorage.getItem("siftlode.configTab.1")).toBeNull();
|
||||
expect(localStorage.getItem("siftlode.configTab")).toBeNull();
|
||||
});
|
||||
|
||||
it("a pre-selected tab is the one the page opens on", () => {
|
||||
|
||||
Reference in New Issue
Block a user