@@ -82,15 +82,15 @@ export async function handleAuth({
8282 request as unknown as SessionManager ,
8383 new URL ( request . url ) ,
8484 ) ;
85- redirectToPostLoginUrl ( ) ;
86- return redirect ( 302 , kindeConfiguration . loginRedirectURL ?? "/" ) ;
85+ await redirectToPostLoginUrl ( ) ;
86+ throw redirect ( 302 , kindeConfiguration . loginRedirectURL || "/" ) ;
8787 case "logout" :
8888 url = await kindeAuthClient . logout ( request as unknown as SessionManager ) ;
8989 break ;
9090 default :
9191 return error ( 404 , "Not Found" ) ;
9292 }
93- redirect ( 302 , url . toString ( ) ) ;
93+ throw redirect ( 302 , url . toString ( ) ) ;
9494}
9595
9696const openPortal = async (
@@ -115,7 +115,7 @@ const openPortal = async (
115115 console . log ( "err:" , err ) ;
116116 throw error ( 500 , "Failed to generate portal URL" ) ;
117117 }
118- redirect ( 302 , portalUrl . url . toString ( ) ) ;
118+ throw redirect ( 302 , portalUrl . url . toString ( ) ) ;
119119} ;
120120
121121const storePostLoginRedirectUrl = (
@@ -136,19 +136,22 @@ const isAbsoluteUrl = (url: string) =>
136136 url . indexOf ( "http://" ) === 0 || url . indexOf ( "https://" ) === 0 ;
137137
138138const redirectToPostLoginUrl = async ( ) => {
139- if ( await sessionStorage . getSessionItem ( KEY_POST_LOGIN_REDIRECT_URL ) ) {
140- const post_login_redirect_url = ( await sessionStorage . getSessionItem (
141- KEY_POST_LOGIN_REDIRECT_URL ,
142- ) ) as string ;
143- sessionStorage . removeSessionItem ( KEY_POST_LOGIN_REDIRECT_URL ) ;
139+ const value = await sessionStorage . getSessionItem (
140+ KEY_POST_LOGIN_REDIRECT_URL ,
141+ ) ;
142+ if ( ! value || typeof value !== "string" ) {
143+ return ;
144+ }
145+ const post_login_redirect_url = value as string ;
146+ sessionStorage . removeSessionItem ( KEY_POST_LOGIN_REDIRECT_URL ) ;
144147
145- if ( isAbsoluteUrl ( post_login_redirect_url ) ) {
146- redirect ( 302 , new URL ( post_login_redirect_url ) ) ;
147- } else {
148- redirect (
149- 302 ,
150- new URL ( post_login_redirect_url , kindeConfiguration . appBase ) ,
151- ) ;
148+ const appBaseUrl = new URL ( kindeConfiguration . appBase ) ;
149+ if ( isAbsoluteUrl ( post_login_redirect_url ) ) {
150+ const target = new URL ( post_login_redirect_url ) ;
151+ if ( target . origin !== appBaseUrl . origin ) {
152+ return ;
152153 }
154+ throw redirect ( 302 , target . toString ( ) ) ;
153155 }
156+ throw redirect ( 302 , new URL ( post_login_redirect_url , appBaseUrl ) . toString ( ) ) ;
154157} ;
0 commit comments