@@ -82,15 +82,15 @@ export async function handleAuth({
82
82
request as unknown as SessionManager ,
83
83
new URL ( request . url ) ,
84
84
) ;
85
- redirectToPostLoginUrl ( ) ;
86
- return redirect ( 302 , kindeConfiguration . loginRedirectURL ?? "/" ) ;
85
+ await redirectToPostLoginUrl ( ) ;
86
+ throw redirect ( 302 , kindeConfiguration . loginRedirectURL || "/" ) ;
87
87
case "logout" :
88
88
url = await kindeAuthClient . logout ( request as unknown as SessionManager ) ;
89
89
break ;
90
90
default :
91
91
return error ( 404 , "Not Found" ) ;
92
92
}
93
- redirect ( 302 , url . toString ( ) ) ;
93
+ throw redirect ( 302 , url . toString ( ) ) ;
94
94
}
95
95
96
96
const openPortal = async (
@@ -115,7 +115,7 @@ const openPortal = async (
115
115
console . log ( "err:" , err ) ;
116
116
throw error ( 500 , "Failed to generate portal URL" ) ;
117
117
}
118
- redirect ( 302 , portalUrl . url . toString ( ) ) ;
118
+ throw redirect ( 302 , portalUrl . url . toString ( ) ) ;
119
119
} ;
120
120
121
121
const storePostLoginRedirectUrl = (
@@ -136,19 +136,22 @@ const isAbsoluteUrl = (url: string) =>
136
136
url . indexOf ( "http://" ) === 0 || url . indexOf ( "https://" ) === 0 ;
137
137
138
138
const 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 ) ;
144
147
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 ;
152
153
}
154
+ throw redirect ( 302 , target . toString ( ) ) ;
153
155
}
156
+ throw redirect ( 302 , new URL ( post_login_redirect_url , appBaseUrl ) . toString ( ) ) ;
154
157
} ;
0 commit comments