Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/app/src/features/auth/account-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ThemeToggle } from "../../shared/theme";
import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
import { useMutation, useQuery } from "@tanstack/react-query";
import { api } from "factorize-api-client";
import { messageOf, refreshIdentity, sessionQuery } from "./session";
import { clearSignedOutIdentity, messageOf, sessionQuery } from "./session";
import { triggerQuery, triggersQuery } from "../triggers/queries";
import { ResourceSwitcher } from "../../shared/resource-switcher";
import beeMark from "../../assets/bee-mark-monochrome.png";
Expand All @@ -25,7 +25,8 @@ export function AccountBar() {
mutationFn: async () => {
const result = await api.POST("/api/v1/auth/logout");
if (result.error) throw new Error(messageOf(result.error));
await refreshIdentity();
await clearSignedOutIdentity();
await navigate({ to: "/", replace: true });
},
});
const [accountOpen, setAccountOpen] = useState(false), [mobileAccountOpen, setMobileAccountOpen] = useState(false);
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/features/auth/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export async function refreshIdentity() {
queryClient.clear();
return queryClient.fetchQuery(sessionQuery);
}
export async function clearSignedOutIdentity() {
await queryClient.cancelQueries();
queryClient.setQueryData(sessionQuery.queryKey, { authenticated: false });
queryClient.removeQueries({ predicate: query => query.queryKey[0] !== "session" });
queryClient.getMutationCache().clear();
}
export function messageOf(error: unknown): string {
if (error && typeof error === "object" && "error" in error) {
const detail = error.error;
Expand Down
54 changes: 54 additions & 0 deletions packages/app/test/functional/signout.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import assert from "node:assert/strict";
import { expect, test } from "./fixtures.mjs";

for (const [layout, viewport] of [["desktop", { width: 1200, height: 900 }], ["mobile", { width: 390, height: 844 }]]) {
test(`${layout} sign-out opens the public landing and Back cannot restore protected data`, async ({ page, origin }) => {
await page.setViewportSize(viewport);
let active = true, signedOutEventReads = 0;
const expiresAt = new Date(Date.now() + 3600_000).toISOString();
await page.route("**/api/v1/session", route => route.fulfill({ json: active ? {
authenticated: true, user: { id: "owner-a", email: "owner@example.test" },
team: { id: "workspace-a", name: "Private Workspace", role: "owner" },
capabilities: ["team:read", "triggers:read", "integrations:read"], expiresAt,
} : { authenticated: false } }));
await page.route("**/api/v1/triggers", route => route.fulfill({ json: [{
id: "private-trigger", name: "Private trigger marker", updatedAt: "2026-11-30T16:00:00Z", sources: [],
}] }));
await page.route("**/api/v1/events", route => {
if (!active) {
signedOutEventReads++;
return route.fulfill({ status: 401, json: { error: { message: "Sign in required." } } });
}
return route.fulfill({ json: [{ id: "private-event", name: "Private event marker", description: "" }] });
});
await page.route("**/api/v1/access/authorized-clients", route => route.fulfill({ json: [] }));
await page.route("**/api/v1/event-subscriptions", route => route.fulfill({ json: [] }));
await page.route("**/api/v1/auth/logout", route => {
active = false;
return route.fulfill({ json: { ok: true } });
});

await page.goto(origin + "/");
await expect(page.getByRole("heading", { name: "Recent work" })).toBeVisible();
await expect(page.getByText("Private trigger marker")).toBeVisible();
const dashboard = page.getByRole("navigation", { name: "Dashboard navigation" });
await dashboard.getByRole("link", { name: "Events", exact: true }).click();
await expect(page.getByText("Private event marker")).toBeVisible();
await dashboard.getByRole("link", { name: "Clients", exact: true }).click();
await expect(page.getByRole("heading", { name: "Clients", exact: true })).toBeVisible();

await page.getByRole("button", { name: "Your account", exact: true }).click();
await page.getByRole("button", { name: "Sign out", exact: true }).click();
await expect(page).toHaveURL(origin + "/");
await expect(page.getByRole("heading", { name: "Welcome to Factorize" })).toBeVisible();
await expect(dashboard).toHaveCount(0);
assert.equal(await page.evaluate(() => localStorage.length), 0);

await page.goBack();
await expect(page).toHaveURL(/\/auth\/login(?:\?|$)/);
await expect(page.getByText("Private event marker")).toHaveCount(0);
await expect(page.getByText("Private trigger marker")).toHaveCount(0);
await expect(dashboard).toHaveCount(0);
assert.equal(signedOutEventReads, 0);
});
}
Loading