mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-17 07:28:46 +00:00
/api/client/[id]/key Endpoint 삭제 및 프론트엔드와의 Zod 스키마 공유 구현
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import ms from "ms";
|
||||
import { z } from "zod";
|
||||
import env from "$lib/server/loadenv";
|
||||
import { loginRequest } from "$lib/server/schemas/auth";
|
||||
import { login } from "$lib/server/services/auth";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
email: z.string().email().nonempty(),
|
||||
password: z.string().trim().nonempty(),
|
||||
})
|
||||
.safeParse(await request.json());
|
||||
const zodRes = loginRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { email, password } = zodRes.data;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { tokenUpgradeRequest, tokenUpgradeResponse } from "$lib/server/schemas/auth";
|
||||
import { createTokenUpgradeChallenge } from "$lib/server/services/auth";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
@@ -7,12 +7,7 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
const token = cookies.get("refreshToken");
|
||||
if (!token) error(401, "Refresh token not found");
|
||||
|
||||
const zodRes = z
|
||||
.object({
|
||||
encPubKey: z.string().base64().nonempty(),
|
||||
sigPubKey: z.string().base64().nonempty(),
|
||||
})
|
||||
.safeParse(await request.json());
|
||||
const zodRes = tokenUpgradeRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { encPubKey, sigPubKey } = zodRes.data;
|
||||
|
||||
@@ -22,5 +17,5 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
encPubKey,
|
||||
sigPubKey,
|
||||
);
|
||||
return json({ challenge });
|
||||
return json(tokenUpgradeResponse.parse({ challenge }));
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { tokenUpgradeVerifyRequest } from "$lib/server/schemas/auth";
|
||||
import { upgradeToken } from "$lib/server/services/auth";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
@@ -7,12 +7,7 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
const token = cookies.get("refreshToken");
|
||||
if (!token) error(401, "Refresh token not found");
|
||||
|
||||
const zodRes = z
|
||||
.object({
|
||||
answer: z.string().base64().nonempty(),
|
||||
sigAnswer: z.string().base64().nonempty(),
|
||||
})
|
||||
.safeParse(await request.json());
|
||||
const zodRes = tokenUpgradeVerifyRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { answer, sigAnswer } = zodRes.data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user