260615_01_FST: First Commit

This commit is contained in:
2026-06-15 09:32:24 +09:00
parent e75c28a7ba
commit 677d678e68
92 changed files with 12081 additions and 233 deletions

41
src/query/auth.ts Normal file
View File

@@ -0,0 +1,41 @@
"use client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { nextApi } from "@/lib/http-client";
import { useAuth } from "@/hooks/useAuth";
import type { LoginUser } from "@/types/auth";
export const useLoginMutation = () => {
const { setFromLoginResponse } = useAuth();
return useMutation({
mutationFn: async (v: { userId: string; userPw: string;}) => {
return nextApi.post<LoginUser>("/login", { userId: v.userId, userPw: v.userPw }, { autoLogoutOnAuthError: false });
},
onSuccess: (data, v) => {
setFromLoginResponse(data);
},
});
}
export const useLogoutMutation = () => {
const qc = useQueryClient();
const { auth, logout } = useAuth();
return useMutation({
mutationFn: async () => {
const userId = auth.user?.userId ?? "";
try {
if (userId){
await nextApi.post(`/logout/${userId}`, null, { autoLogoutOnAuthError: false });
}
} catch (e) {
console.error(e);
}
},
onSettled: () => {
logout();
qc.clear(); // 다음 사용자/세션에 서버상태 남지 않게
},
});
}