refactor: do not force redirects to happen on the server (#481)

This commit is contained in:
Alessandro (Ale) Segala
2025-04-25 04:09:52 +09:00
committed by GitHub
parent 8e66af627a
commit 662506260e
10 changed files with 31 additions and 26 deletions

View File

@@ -27,13 +27,11 @@ const authenticationHandle: Handle = async ({ event, resolve }) => {
const isPublicPath = ['/authorize', '/health'].includes(event.url.pathname);
const isAdminPath = event.url.pathname.startsWith('/settings/admin');
if (!isUnauthenticatedOnlyPath && !isPublicPath) {
if (!isSignedIn) {
return new Response(null, {
status: 302,
headers: { location: '/login' }
});
}
if (!isUnauthenticatedOnlyPath && !isPublicPath && !isSignedIn) {
return new Response(null, {
status: 302,
headers: { location: '/login' }
});
}
if (isUnauthenticatedOnlyPath && isSignedIn) {
@@ -81,7 +79,7 @@ function verifyJwt(accessToken: string | undefined) {
const jwtPayload = decodeJwt<{ isAdmin: boolean }>(accessToken);
if (jwtPayload?.exp && jwtPayload.exp * 1000 > Date.now()) {
isSignedIn = true;
isAdmin = jwtPayload?.isAdmin || false;
isAdmin = !!(jwtPayload?.isAdmin);
}
}