/api/client/[id]/key Endpoint 삭제 및 프론트엔드와의 Zod 스키마 공유 구현

This commit is contained in:
static
2025-01-02 04:44:02 +09:00
parent 45df24b416
commit b07d67b958
27 changed files with 241 additions and 169 deletions

View File

@@ -1,6 +1,6 @@
import { error, json } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { clientRegisterRequest, clientRegisterResponse } from "$lib/server/schemas/client";
import { registerUserClient } from "$lib/server/services/client";
import type { RequestHandler } from "./$types";
@@ -10,15 +10,10 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
error(403, "Forbidden");
}
const zodRes = z
.object({
encPubKey: z.string().base64().nonempty(),
sigPubKey: z.string().base64().nonempty(),
})
.safeParse(await request.json());
const zodRes = clientRegisterRequest.safeParse(await request.json());
if (!zodRes.success) error(400, "Invalid request body");
const { encPubKey, sigPubKey } = zodRes.data;
const { challenge } = await registerUserClient(userId, getClientAddress(), encPubKey, sigPubKey);
return json({ challenge });
return json(clientRegisterResponse.parse({ challenge }));
};