/api/key 경로에 있는 Endpoint들을 /api/client 경로로 이동

This commit is contained in:
static
2024-12-29 19:12:50 +09:00
parent bbba449819
commit 3664ad66ac
4 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,23 @@
import { error, text } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { verifyUserClient } from "$lib/server/services/client";
import type { RequestHandler } from "./$types";
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
const zodRes = z
.object({
answer: z.string().base64().nonempty(),
})
.safeParse(await request.json());
if (!zodRes.success) error(400, "Invalid request body");
const { userId, clientId } = authenticate(cookies);
if (clientId) {
error(403, "Forbidden");
}
const { answer } = zodRes.data;
await verifyUserClient(userId, getClientAddress(), answer.trim());
return text("Client verified", { headers: { "Content-Type": "text/plain" } });
};