File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ export interface MobileSession {
33 s ?: string
44}
55
6+ // In-memory cache: survives SPA navigations without localStorage
7+ let cachedSession : MobileSession | null | undefined
8+
69// Helper that parses the state param from the OAuth callback (same pattern as extractRedirectToFromSearchParameters)
710function extractMobileDataFromState ( ) : { isMobileFlow ?: boolean ; mobileUserId ?: string ; mobileSessionId ?: string } | null {
811 try {
@@ -24,20 +27,26 @@ function extractMobileDataFromState(): { isMobileFlow?: boolean; mobileUserId?:
2427}
2528
2629export function getMobileSession ( ) : MobileSession | null {
30+ if ( cachedSession !== undefined ) {
31+ return cachedSession
32+ }
33+
2734 const params = new URLSearchParams ( window . location . search )
2835
2936 // On /auth/mobile, read from URL params
3037 if ( window . location . pathname . startsWith ( '/auth/mobile' ) ) {
31- return { u : params . get ( 'u' ) ?? undefined , s : params . get ( 's' ) ?? undefined }
38+ cachedSession = { u : params . get ( 'u' ) ?? undefined , s : params . get ( 's' ) ?? undefined }
39+ return cachedSession
3240 }
3341
3442 // On callback, extract from OAuth state param
3543 const stateData = extractMobileDataFromState ( )
3644 if ( stateData ?. isMobileFlow ) {
37- return {
45+ cachedSession = {
3846 u : stateData . mobileUserId ?? undefined ,
3947 s : stateData . mobileSessionId ?? undefined
4048 }
49+ return cachedSession
4150 }
4251
4352 return null
You can’t perform that action at this time.
0 commit comments