@@ -54,6 +54,11 @@ const ACCESS_CHECKING_NOTICE_ID = "access-checking";
5454const AUTH_DEGRADED_NOTICE_ID = "auth-degraded" ;
5555const OFFLINE_SYNC_NOTICE_ID = "offline-sync" ;
5656const 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."
0 commit comments