Skip to content

Commit 8a0f947

Browse files
committed
fix: improve error state and redirect handling
1 parent efb186f commit 8a0f947

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/handlers/callback.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,19 @@ export const callback = async (routerClient: RouterClient) => {
1818
if (errorParam?.toLowerCase() === "login_link_expired") {
1919
const reauthState = routerClient.getSearchParam("reauth_state");
2020
if (reauthState) {
21-
const decodedAuthState = atob(reauthState);
2221
try {
23-
const reauthState = JSON.parse(decodedAuthState);
24-
if (reauthState) {
25-
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);
2626
const loginRoute = new URL(
2727
`${config.redirectURL}${config.apiPath}/${routes.login}`,
2828
);
2929
loginRoute.search = urlParams.toString();
3030
return routerClient.redirect(loginRoute.toString());
3131
}
32-
} catch (ex) {
33-
throw new Error(
34-
ex instanceof Error
35-
? ex.message
36-
: "Unknown Error parsing reauth state",
37-
);
32+
} catch {
33+
return redirectToLogin(routerClient);
3834
}
3935
}
4036
return redirectToLogin(routerClient);

0 commit comments

Comments
 (0)