mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
/api/auth/changePassword, /api/user, /api/user/changeNickname Endpoint 구현
This commit is contained in:
16
src/routes/api/auth/changePassword/+server.ts
Normal file
16
src/routes/api/auth/changePassword/+server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { changePasswordRequest } from "$lib/server/schemas";
|
||||
import { changePassword } from "$lib/server/services/auth";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ locals, request }) => {
|
||||
const { sessionId, userId } = await authorize(locals, "any");
|
||||
|
||||
const zodRes = changePasswordRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { oldPassword, newPassword } = zodRes.data;
|
||||
|
||||
await changePassword(userId, sessionId, oldPassword, newPassword);
|
||||
return text("Password changed", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
11
src/routes/api/user/+server.ts
Normal file
11
src/routes/api/user/+server.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { userInfoResponse, type UserInfoResponse } from "$lib/server/schemas";
|
||||
import { getUserInformation } from "$lib/server/services/user";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const GET: RequestHandler = async ({ locals }) => {
|
||||
const { userId } = await authorize(locals, "any");
|
||||
const { email, nickname } = await getUserInformation(userId);
|
||||
return json(userInfoResponse.parse({ email, nickname } satisfies UserInfoResponse));
|
||||
};
|
||||
16
src/routes/api/user/changeNickname/+server.ts
Normal file
16
src/routes/api/user/changeNickname/+server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { changeNicknameRequest } from "$lib/server/schemas";
|
||||
import { changeNickname } from "$lib/server/services/user";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ locals, request }) => {
|
||||
const { userId } = await authorize(locals, "any");
|
||||
|
||||
const zodRes = changeNicknameRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { newNickname } = zodRes.data;
|
||||
|
||||
await changeNickname(userId, newNickname);
|
||||
return text("Nickname changed", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
Reference in New Issue
Block a user