@@ -19,29 +19,68 @@ export function getUrlToken():
1919 return undefined ;
2020 }
2121
22- const queryString = window . location . search ;
23- const params = new URLSearchParams ( queryString ) ;
24- const authResultString = params . get ( "authResult" ) ;
25- const walletId = params . get ( "walletId" ) as WalletId | undefined ;
26- const authProvider = params . get ( "authProvider" ) as AuthOption | undefined ;
27- const authCookie = params . get ( "authCookie" ) as string | undefined ;
28- const authFlow = params . get ( "authFlow" ) as "connect" | "link" | undefined ;
22+ // Read params from the standard query string
23+ const params = new URLSearchParams ( window . location . search ) ;
24+
25+ // Also check for params embedded inside the hash fragment (e.g. #/route?walletId=...)
26+ // This supports hash-routed apps where params may be placed after the hash path
27+ let hashParams : URLSearchParams | undefined ;
28+ const hash = window . location . hash || "" ;
29+ let cleanHash = hash ;
30+ const hashQueryIndex = hash . indexOf ( "?" ) ;
31+ if ( hashQueryIndex !== - 1 ) {
32+ hashParams = new URLSearchParams ( hash . substring ( hashQueryIndex ) ) ;
33+ cleanHash = hash . substring ( 0 , hashQueryIndex ) ;
34+ }
35+
36+ const walletId = ( params . get ( "walletId" ) ??
37+ hashParams ?. get ( "walletId" ) ??
38+ undefined ) as WalletId | undefined ;
39+ const authResultString =
40+ params . get ( "authResult" ) ?? hashParams ?. get ( "authResult" ) ?? undefined ;
41+ const authProvider = ( params . get ( "authProvider" ) ??
42+ hashParams ?. get ( "authProvider" ) ??
43+ undefined ) as AuthOption | undefined ;
44+ const authCookie = ( params . get ( "authCookie" ) ??
45+ hashParams ?. get ( "authCookie" ) ??
46+ undefined ) as string | undefined ;
47+ const authFlow = ( params . get ( "authFlow" ) ??
48+ hashParams ?. get ( "authFlow" ) ??
49+ undefined ) as "connect" | "link" | undefined ;
2950
3051 if ( ( authCookie || authResultString ) && walletId ) {
3152 const authResult = ( ( ) => {
3253 if ( authResultString ) {
3354 params . delete ( "authResult" ) ;
55+ hashParams ?. delete ( "authResult" ) ;
3456 return JSON . parse ( decodeURIComponent ( authResultString ) ) ;
3557 }
3658 } ) ( ) ;
3759 params . delete ( "walletId" ) ;
3860 params . delete ( "authProvider" ) ;
3961 params . delete ( "authCookie" ) ;
4062 params . delete ( "authFlow" ) ;
63+ hashParams ?. delete ( "walletId" ) ;
64+ hashParams ?. delete ( "authProvider" ) ;
65+ hashParams ?. delete ( "authCookie" ) ;
66+ hashParams ?. delete ( "authFlow" ) ;
67+
68+ const remainingSearch = params . toString ( ) ;
69+ const searchString = remainingSearch ? `?${ remainingSearch } ` : "" ;
70+
71+ // Reconstruct hash, preserving the hash path and any remaining non-auth params
72+ let hashString = cleanHash ;
73+ if ( hashParams ) {
74+ const remainingHashParams = hashParams . toString ( ) ;
75+ if ( remainingHashParams ) {
76+ hashString = `${ cleanHash } ?${ remainingHashParams } ` ;
77+ }
78+ }
79+
4180 window . history . pushState (
4281 { } ,
4382 "" ,
44- `${ window . location . pathname } ? ${ params . toString ( ) } ` ,
83+ `${ window . location . pathname } ${ searchString } ${ hashString } ` ,
4584 ) ;
4685 return { authCookie, authFlow, authProvider, authResult, walletId } ;
4786 }
0 commit comments