mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
Access Token 유무에 따른 자동 리다이렉트 구현
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { ServerInit } from "@sveltejs/kit";
|
||||
import { redirect, type ServerInit, type Handle } from "@sveltejs/kit";
|
||||
import schedule from "node-schedule";
|
||||
import { cleanupExpiredRefreshTokens } from "$lib/server/db/token";
|
||||
|
||||
@@ -7,3 +7,17 @@ export const init: ServerInit = () => {
|
||||
cleanupExpiredRefreshTokens();
|
||||
});
|
||||
};
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
const path = event.url.pathname;
|
||||
if (path.startsWith("/api") || path.startsWith("/auth")) {
|
||||
return await resolve(event);
|
||||
}
|
||||
|
||||
const accessToken = event.cookies.get("accessToken");
|
||||
if (accessToken) {
|
||||
return await resolve(event);
|
||||
} else {
|
||||
redirect(302, "/auth/login?redirect=" + encodeURIComponent(path));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user