Skip to content

Commit fee7503

Browse files
author
Alexis
committed
fix: address coderabbit comments about session storage calls and throwing redirects
1 parent e8b5c8f commit fee7503

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/lib/handleAuth/handleAuth.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ export async function handleAuth({
8383
new URL(request.url),
8484
);
8585
await redirectToPostLoginUrl();
86-
return redirect(302, kindeConfiguration.loginRedirectURL ?? "/");
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

9696
const 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

121121
const storePostLoginRedirectUrl = (
@@ -136,19 +136,18 @@ const isAbsoluteUrl = (url: string) =>
136136
url.indexOf("http://") === 0 || url.indexOf("https://") === 0;
137137

138138
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);
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-
);
152-
}
148+
if (isAbsoluteUrl(post_login_redirect_url)) {
149+
redirect(302, new URL(post_login_redirect_url));
150+
} else {
151+
redirect(302, new URL(post_login_redirect_url, kindeConfiguration.appBase));
153152
}
154153
};

0 commit comments

Comments
 (0)