@@ -27,6 +27,8 @@ export interface InvitePayload {
2727}
2828
2929const INVITE_STORAGE_KEY = "invite"
30+ const POST_SIGNUP_PENDING_KEY = "postSignupPending"
31+ const POST_SIGNUP_TTL_MS = 2 * 60 * 1000
3032let authOrgFetchInFlight = false
3133
3234export const protectedRouteReadyAtom = atom ( false )
@@ -99,6 +101,41 @@ export const isCurrentAcceptRouteForInvite = (appState: any, invite: InvitePaylo
99101 return currentToken === invite . token
100102}
101103
104+ export const writePostSignupPending = ( ) => {
105+ if ( ! isBrowser ) return
106+ try {
107+ window . sessionStorage . setItem (
108+ POST_SIGNUP_PENDING_KEY ,
109+ JSON . stringify ( { ts : Date . now ( ) } ) ,
110+ )
111+ } catch {
112+ // ignore storage failures
113+ }
114+ }
115+
116+ const readPostSignupPending = ( ) : boolean => {
117+ if ( ! isBrowser ) return false
118+ try {
119+ const raw = window . sessionStorage . getItem ( POST_SIGNUP_PENDING_KEY )
120+ if ( ! raw ) return false
121+ const parsed = JSON . parse ( raw ) as { ts ?: number }
122+ if ( ! parsed ?. ts ) return false
123+ if ( Date . now ( ) - parsed . ts > POST_SIGNUP_TTL_MS ) return false
124+ return true
125+ } catch {
126+ return false
127+ }
128+ }
129+
130+ const clearPostSignupPending = ( ) => {
131+ if ( ! isBrowser ) return
132+ try {
133+ window . sessionStorage . removeItem ( POST_SIGNUP_PENDING_KEY )
134+ } catch {
135+ // ignore storage failures
136+ }
137+ }
138+
102139export const syncAuthStateFromUrl = ( nextUrl ?: string ) => {
103140 if ( ! isBrowser ) return
104141
@@ -148,11 +185,22 @@ export const syncAuthStateFromUrl = (nextUrl?: string) => {
148185 asPath,
149186 baseAppURL,
150187 } )
188+ clearPostSignupPending ( )
151189 }
152190 if ( isAuthCallbackRoute ) {
153191 store . set ( protectedRouteReadyAtom , false )
154192 return
155193 }
194+ if ( isAuthRoute ) {
195+ if ( readPostSignupPending ( ) ) {
196+ clearPostSignupPending ( )
197+ void Router . replace ( "/post-signup" ) . catch ( ( error ) => {
198+ console . error ( "Failed to redirect to post-signup:" , error )
199+ } )
200+ store . set ( protectedRouteReadyAtom , false )
201+ return
202+ }
203+ }
156204 if ( typeof window !== "undefined" ) {
157205 const upgradeOrgId = window . localStorage . getItem ( "authUpgradeOrgId" )
158206 const identifiers = store . get ( appIdentifiersAtom )
0 commit comments