mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-18 17:23:26 +03:00
refactor: do not force redirects to happen on the server (#481)
This commit is contained in:
committed by
GitHub
parent
8e66af627a
commit
662506260e
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user