mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
공개 키 등록 구현
This commit is contained in:
22
src/routes/api/key/register/+server.ts
Normal file
22
src/routes/api/key/register/+server.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authenticate } from "$lib/server/modules/auth";
|
||||
import { registerPubKey } from "$lib/server/services/key";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
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(request);
|
||||
if (clientId) {
|
||||
error(403, "Forbidden");
|
||||
}
|
||||
|
||||
await registerPubKey(userId, zodRes.data.pubKey);
|
||||
return text("Public key registered");
|
||||
};
|
||||
Reference in New Issue
Block a user