공개 키 등록시 인증 절차 추가

This commit is contained in:
static
2024-12-29 00:32:24 +09:00
parent 928cb799d3
commit 75ab5f5859
11 changed files with 183 additions and 22 deletions

View File

@@ -1,10 +1,10 @@
import { error, text } from "@sveltejs/kit";
import { error, json } 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, cookies }) => {
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
const zodRes = z
.object({
pubKey: z.string().base64().nonempty(),
@@ -17,6 +17,6 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
error(403, "Forbidden");
}
await registerPubKey(userId, zodRes.data.pubKey);
return text("Public key registered", { headers: { "Content-Type": "text/plain" } });
const challenge = await registerPubKey(userId, getClientAddress(), zodRes.data.pubKey);
return json({ challenge });
};