암호 키 유무에 따른 자동 리다이렉션 구현

This commit is contained in:
static
2024-12-28 18:55:20 +09:00
parent 173f4f5cfe
commit dfb56b62b1
4 changed files with 29 additions and 8 deletions

View File

@@ -9,8 +9,7 @@ export const init: ServerInit = () => {
};
export const handle: Handle = async ({ event, resolve }) => {
const path = event.url.pathname;
if (path.startsWith("/api") || path.startsWith("/auth")) {
if (["/api", "/auth"].some((path) => event.url.pathname.startsWith(path))) {
return await resolve(event);
}
@@ -18,6 +17,9 @@ export const handle: Handle = async ({ event, resolve }) => {
if (accessToken) {
return await resolve(event);
} else {
redirect(302, "/auth/login?redirect=" + encodeURIComponent(path));
redirect(
302,
"/auth/login?redirect=" + encodeURIComponent(event.url.pathname + event.url.search),
);
}
};