mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
24 lines
805 B
TypeScript
24 lines
805 B
TypeScript
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" } });
|
|
};
|