mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
21 lines
831 B
TypeScript
21 lines
831 B
TypeScript
import { error, json } from "@sveltejs/kit";
|
|
import { authorize } from "$lib/server/modules/auth";
|
|
import {
|
|
clientRegisterRequest,
|
|
clientRegisterResponse,
|
|
type ClientRegisterResponse,
|
|
} from "$lib/server/schemas";
|
|
import { registerUserClient } from "$lib/server/services/client";
|
|
import type { RequestHandler } from "./$types";
|
|
|
|
export const POST: RequestHandler = async ({ locals, request }) => {
|
|
const { userId } = await authorize(locals, "notClient");
|
|
|
|
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, locals.ip, encPubKey, sigPubKey);
|
|
return json(clientRegisterResponse.parse({ challenge } satisfies ClientRegisterResponse));
|
|
};
|