프론트엔드에서 세션 ID 기반 인증 대응 및 DB 마이그레이션 스크립트 재생성

This commit is contained in:
static
2025-01-12 08:31:11 +09:00
parent be8587694e
commit 85ebb529ba
14 changed files with 141 additions and 155 deletions

View File

@@ -1,11 +1,9 @@
import { error, redirect, type Handle } from "@sveltejs/kit";
import { authenticate, AuthenticationError } from "$lib/server/modules/auth";
const whitelist = ["/auth/login", "/api/auth/login"];
export const authenticateMiddleware: Handle = async ({ event, resolve }) => {
const { pathname, search } = event.url;
if (whitelist.some((path) => pathname.startsWith(path))) {
if (pathname === "/api/auth/login") {
return await resolve(event);
}
@@ -19,7 +17,9 @@ export const authenticateMiddleware: Handle = async ({ event, resolve }) => {
event.locals.session = await authenticate(sessionIdSigned, ip, userAgent);
} catch (e) {
if (e instanceof AuthenticationError) {
if (pathname.startsWith("/api")) {
if (pathname === "/auth/login") {
return await resolve(event);
} else if (pathname.startsWith("/api")) {
error(e.status, e.message);
} else {
redirect(302, "/auth/login?redirect=" + encodeURIComponent(pathname + search));

View File

@@ -17,7 +17,7 @@ export const verifyClientEncMekSig = async (
) => {
const userClient = await getUserClientWithDetails(userId, clientId);
if (!userClient) {
error(500, "Invalid access token");
error(500, "Invalid session id");
}
const data = JSON.stringify({ version, key: encMek });

View File

@@ -98,7 +98,7 @@ export const verifyUserClient = async (
export const getUserClientStatus = async (userId: number, clientId: number) => {
const userClient = await getUserClient(userId, clientId);
if (!userClient) {
error(500, "Invalid access token");
error(500, "Invalid session id");
}
return {