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: 4 additions & 1 deletion csv-table-hub-main/src/__tests__/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ describe("requireSession (route guard)", () => {
thrown = e;
}
expect(isRedirect(thrown)).toBe(true);
expect((thrown as { options: { to: string } }).options.to).toBe("/auth");
const { options } = thrown as { options: { to: string; reloadDocument?: boolean } };
expect(options.to).toBe("/auth");
// #133: a client-side redirect during hydration crashed the router (React #520/#422).
expect(options.reloadDocument).toBe(true);
});

it("lets a signed-in user through", () => {
Expand Down
6 changes: 4 additions & 2 deletions csv-table-hub-main/src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ export function authHeaders(): Record<string, string> {
return s ? { Authorization: `Bearer ${s.token}` } : {};
}

/** Route guard (#96): send anyone without a live session to the sign-in page. */
/** Route guard (#96): send anyone without a live session to the sign-in page.
* A full page load, not a client-side redirect: redirecting while the first
* page hydrates broke the router's match tree (React #520/#422, #133). */
export function requireSession(): void {
if (!getSession()) throw redirect({ to: "/auth" });
if (!getSession()) throw redirect({ to: "/auth", reloadDocument: true });
}

/** Change your own password (#117). This session stays; the server ends all others. */
Expand Down
Loading