Skip to content

Commit f312f07

Browse files
committed
Merge branch 'fix/session-gate-reload-fix' into develop
2 parents b264979 + f4c23ab commit f312f07

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

packages/web/src/features/auth/session-gate.test.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
22
import { createStore, Provider } from "jotai";
33
import { MemoryRouter } from "react-router-dom";
4-
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import { activationStatusAtom } from "../../atoms/activation";
66
import { authEnabledAtom } from "../../atoms/connection";
77
import { SessionGatePage } from "./session-gate";
88

99
const originalFetch = globalThis.fetch;
10+
const originalLocation = window.location;
1011

1112
describe("SessionGatePage", () => {
13+
beforeEach(() => {
14+
Object.defineProperty(window, "location", {
15+
configurable: true,
16+
value: {
17+
...originalLocation,
18+
replace: vi.fn(),
19+
reload: vi.fn(),
20+
},
21+
});
22+
});
23+
1224
afterEach(() => {
1325
globalThis.fetch = originalFetch;
26+
Object.defineProperty(window, "location", {
27+
configurable: true,
28+
value: originalLocation,
29+
});
1430
});
1531

1632
it("shows a password form when auth is enabled", () => {
@@ -78,7 +94,7 @@ describe("SessionGatePage", () => {
7894
});
7995
});
8096

81-
it("navigates back to / after successful re-entry when auth is disabled", async () => {
97+
it("reloads the app after successful re-entry when auth is disabled", async () => {
8298
const requestReentry = vi.fn().mockResolvedValue(true);
8399
const store = createStore();
84100
store.set(authEnabledAtom, false);
@@ -96,6 +112,7 @@ describe("SessionGatePage", () => {
96112

97113
await waitFor(() => {
98114
expect(requestReentry).toHaveBeenCalledTimes(1);
115+
expect(window.location.replace).toHaveBeenCalledWith("/");
99116
});
100117
});
101118
});

packages/web/src/features/auth/session-gate.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useAtomValue } from "jotai";
22
import { useState } from "react";
3-
import { useNavigate } from "react-router-dom";
43
import { authEnabledAtom } from "../../atoms/connection";
54
import { Button, EmptyState } from "../../components/ui";
65
import { useActivation } from "../../hooks/use-activation";
@@ -18,7 +17,6 @@ const gateEmptyStateStyle = {
1817

1918
export function SessionGatePage({ requestReentry }: { requestReentry?: () => Promise<boolean> }) {
2019
const t = useTranslation();
21-
const navigate = useNavigate();
2220
const authEnabled = useAtomValue(authEnabledAtom);
2321
const { claim } = useActivation();
2422
const isMobile = useViewport() === "mobile";
@@ -29,7 +27,7 @@ export function SessionGatePage({ requestReentry }: { requestReentry?: () => Pro
2927
try {
3028
const ok = requestReentry ? await requestReentry() : await claim();
3129
if (ok) {
32-
navigate("/", { replace: true });
30+
window.location.replace("/");
3331
}
3432
} finally {
3533
setSubmitting(false);

0 commit comments

Comments
 (0)