Skip to content

Commit 37cfd9b

Browse files
committed
Fix Firefox staging sign-in redirect
1 parent 25e51c7 commit 37cfd9b

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

src/components/AppShell.deeplink.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ vi.mock("./app-shell/useOnboardingFlow", () => ({
147147
}),
148148
}));
149149

150-
import { AppShell } from "./AppShell";
150+
import { AppShell, buildAuthStartPath } from "./AppShell";
151151

152152
const waitForCondition = async (check: () => boolean, timeoutMs = 2500): Promise<void> => {
153153
const started = Date.now();
@@ -284,6 +284,12 @@ describe("AppShell deeplink cold-load flow", () => {
284284
window.history.replaceState(null, "", "/H%C3%B8gevarde-hyttefelt/Fyrisj%C3%B8vegen");
285285
});
286286

287+
it("builds direct auth-start navigation for explicit sign-in clicks", () => {
288+
expect(buildAuthStartPath({ pathname: "/sim/site", search: "?mode=demo", hash: "#panel" })).toBe(
289+
"/api/auth-start?returnTo=%2Fsim%2Fsite%3Fmode%3Ddemo%23panel",
290+
);
291+
});
292+
287293
it("loads the resolved simulation id and does not emit unavailable", async () => {
288294
const view = await renderAppShell();
289295

src/components/AppShell.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const ACCESS_CHECKING_NOTICE_ID = "access-checking";
5454
const AUTH_DEGRADED_NOTICE_ID = "auth-degraded";
5555
const OFFLINE_SYNC_NOTICE_ID = "offline-sync";
5656
const BLANK_SIM_NOTICE_ID = "blank-simulation-guidance";
57+
58+
export const buildAuthStartPath = (location: Pick<Location, "pathname" | "search" | "hash">): string => {
59+
const returnTo = `${location.pathname}${location.search}${location.hash}`;
60+
return `/api/auth-start?returnTo=${encodeURIComponent(returnTo || "/")}`;
61+
};
5762
// Shell vocabulary mapping for cleanup work:
5863
// - navigator => LeftSidePanel
5964
// - inspector => RightSidePanel (legacy term retained in code for stability)
@@ -275,7 +280,6 @@ export function AppShell() {
275280
const authRetryQuickAttemptRef = useRef(0);
276281
const authRetryTimerRef = useRef<number | null>(null);
277282
const authCheckGenerationRef = useRef(0);
278-
const userInitiatedSignInRef = useRef(false);
279283
const runAccessCheckRef = useRef<(reason: "initial" | "retry" | "online") => void>(() => {});
280284
const setShowWelcomeModalRef = useRef<(show: boolean) => void>(() => {});
281285
const isInitializingRef = useRef(isInitializing);
@@ -559,9 +563,8 @@ export function AppShell() {
559563
}, []);
560564

561565
const handleUserSignInRequested = useCallback(() => {
562-
userInitiatedSignInRef.current = true;
563566
clearAuthRetryTimer();
564-
runAccessCheckRef.current("retry");
567+
window.location.href = buildAuthStartPath(window.location);
565568
}, [clearAuthRetryTimer]);
566569

567570
const scheduleAuthRecoveryRetry = useCallback(
@@ -611,7 +614,6 @@ export function AppShell() {
611614
authRecoveryActiveRef.current = false;
612615
authRecoveryDisabledRef.current = false;
613616
authRetryQuickAttemptRef.current = 0;
614-
userInitiatedSignInRef.current = false;
615617
setAccessDiagnosticMessage(null);
616618
setCurrentUser(profile);
617619
setAuthState("signed_in");
@@ -686,12 +688,6 @@ export function AppShell() {
686688
online: typeof navigator === "undefined" ? true : navigator.onLine,
687689
isInitializing: isInitializingRef.current,
688690
});
689-
if (userInitiatedSignInRef.current) {
690-
userInitiatedSignInRef.current = false;
691-
const returnTo = `${window.location.pathname}${window.location.search}${window.location.hash}`;
692-
window.location.href = `/api/auth-start?returnTo=${encodeURIComponent(returnTo || "/")}`;
693-
return;
694-
}
695691
setAuthDegraded(
696692
"Cloud save is unavailable. Your changes may not be saved. The sign-in check timed out; LinkSim is retrying automatically.",
697693
"timeout",
@@ -799,12 +795,6 @@ export function AppShell() {
799795
setAccessState("readonly");
800796
return;
801797
}
802-
if (userInitiatedSignInRef.current) {
803-
userInitiatedSignInRef.current = false;
804-
const returnTo = `${window.location.pathname}${window.location.search}${window.location.hash}`;
805-
window.location.href = `/api/auth-start?returnTo=${encodeURIComponent(returnTo || "/")}`;
806-
return;
807-
}
808798
setAuthDegraded(
809799
isServerTimeout
810800
? "Cloud save is unavailable. Your changes may not be saved. The sign-in service timed out; LinkSim is retrying automatically."

src/components/UserAdminPanel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ type UserAdminPanelProps = {
8181
*/
8282
onOpenSettings?: () => void;
8383
/**
84-
* When provided, clicking "Sign in" triggers a silent auth check first;
85-
* only if that fails does it redirect to the CF Access login page.
84+
* When provided, clicking "Sign in" delegates sign-in handling to the shell.
8685
*/
8786
onSignInRequested?: () => void;
8887
};

0 commit comments

Comments
 (0)