@@ -142,27 +142,30 @@ function RootLayout() {
142142 } ;
143143
144144 const handleCloseModal = ( redirectUrl ?: string ) => {
145- // Handle external redirect (e.g., http://localhost:19999 )
145+ // Case 1: External redirect (e.g., http://localhost:29999 from install script )
146146 if ( redirectUrl && isAllowedExternalRedirect ( redirectUrl ) ) {
147+ const bearerToken = `Bearer ${ accessToken } ` ;
148+ const encodedToken = btoa ( bearerToken ) ;
147149 const target = new URL ( redirectUrl ) ;
148- target . searchParams . set ( "token" , `Bearer ${ accessToken } ` ) ;
150+ target . searchParams . set ( "token" , encodedToken ) ;
149151 window . location . href = target . toString ( ) ;
150152 return ;
151153 }
152154
153- if ( location . pathname === "/login" ) {
154- if ( redirectUrl && redirectUrl . startsWith ( "/" ) ) {
155- router . navigate ( { to : redirectUrl } ) ;
156- }
155+ // Case 2: Internal redirect path (e.g., /dashboard)
156+ if ( redirectUrl && redirectUrl . startsWith ( "/" ) ) {
157+ router . navigate ( { to : redirectUrl } ) ;
157158 return ;
158159 }
159160
160- if ( redirectUrl && redirectUrl . startsWith ( "/" ) ) {
161- router . navigate ( { to : redirectUrl } ) ;
161+ // Case 3: Modal login (/?modal=login) - close modal and go to homepage
162+ // Or /login route without redirect - go to homepage
163+ if ( location . pathname === "/login" ) {
164+ router . navigate ( { to : "/" } ) ;
162165 return ;
163166 }
164167
165- // Remove the modal search param by navigating without it
168+ // Case 4: Modal was opened on another page - just close modal, stay on current page
166169 const url = new URL ( window . location . href ) ;
167170 url . searchParams . delete ( URL_PARAM . MODAL ) ;
168171 url . searchParams . delete ( URL_PARAM . REDIRECT ) ;
0 commit comments