mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
/api/key 경로에 있는 Endpoint들을 /api/client 경로로 이동
This commit is contained in:
23
src/routes/api/client/register/+server.ts
Normal file
23
src/routes/api/client/register/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authenticate } from "$lib/server/modules/auth";
|
||||
import { registerUserClient } from "$lib/server/services/client";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
pubKey: 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 { pubKey } = zodRes.data;
|
||||
const challenge = await registerUserClient(userId, getClientAddress(), pubKey.trim());
|
||||
return json({ challenge });
|
||||
};
|
||||
Reference in New Issue
Block a user