Skip to content

Commit fe6403f

Browse files
authored
Merge pull request #450 from kinde-oss/fix/prompt-none
fix: when prompt none failed with no session redirect to login
2 parents c7018ea + 8a0f947 commit fe6403f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/handlers/callback.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
import { config, routes } from "../config/index";
22
import RouterClient from "../routerClients/RouterClient";
33

4+
const redirectToLogin = (routerClient: RouterClient) => {
5+
const loginUrl = new URL(
6+
`${config.redirectURL}${config.apiPath}/${routes.login}`,
7+
);
8+
const state = routerClient.getSearchParam("state");
9+
if (state) {
10+
loginUrl.searchParams.set("state", state);
11+
}
12+
return routerClient.redirect(loginUrl.toString());
13+
};
14+
415
export const callback = async (routerClient: RouterClient) => {
516
const errorParam = routerClient.getSearchParam("error");
617
if (errorParam) {
718
if (errorParam?.toLowerCase() === "login_link_expired") {
819
const reauthState = routerClient.getSearchParam("reauth_state");
920
if (reauthState) {
10-
const decodedAuthState = atob(reauthState);
1121
try {
12-
const reauthState = JSON.parse(decodedAuthState);
13-
if (reauthState) {
14-
const urlParams = new URLSearchParams(reauthState);
22+
const decodedAuthState = atob(reauthState);
23+
const parsedReauthState = JSON.parse(decodedAuthState);
24+
if (parsedReauthState) {
25+
const urlParams = new URLSearchParams(parsedReauthState);
1526
const loginRoute = new URL(
1627
`${config.redirectURL}${config.apiPath}/${routes.login}`,
1728
);
1829
loginRoute.search = urlParams.toString();
1930
return routerClient.redirect(loginRoute.toString());
2031
}
21-
} catch (ex) {
22-
throw new Error(
23-
ex instanceof Error
24-
? ex.message
25-
: "Unknown Error parsing reauth state",
26-
);
32+
} catch {
33+
return redirectToLogin(routerClient);
2734
}
2835
}
29-
return;
36+
return redirectToLogin(routerClient);
3037
}
31-
return;
38+
return redirectToLogin(routerClient);
3239
}
3340

3441
const postLoginRedirectURLFromMemory =

0 commit comments

Comments
 (0)