-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: React Query로 로그인 기능 통합 및 hooks 폴더명 수정
- hook ⇨ hooks로 폴더명 변경 - 로그인 로직을 React Query의 useMutation으로 리팩토링 - 로컬 로그인 오류 상태 관리 제거 - 로그인 실패 시 toast 알림을 통한 오류 처리 추가 - useSignup을 useAuth로 통합하여 인증 처리 통일 - LoginForm 컴포넌트를 새로운 useAuth 훅을 사용하도록 업데이트
- Loading branch information
Showing
9 changed files
with
47 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useRouter } from "next/navigation"; | ||
import { toast } from "react-toastify"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
import { signup } from "@/api/authAPI"; | ||
import { ErrorType } from "@/api/goalAPI"; | ||
import { poof } from "@/utils/confetti"; | ||
import { login } from "@/utils/authUtils"; | ||
|
||
export const useAuth = () => { | ||
const router = useRouter(); | ||
|
||
const signupMutation = useMutation({ | ||
mutationFn: signup, | ||
onSuccess: () => { | ||
toast.success("회원가입이 완료되었습니다."); | ||
poof(); | ||
router.push("/login"); | ||
}, | ||
onError: (error: ErrorType) => { | ||
throw error; | ||
}, | ||
}); | ||
|
||
const loginMutation = useMutation({ | ||
mutationFn: (data: { email: string; password: string }) => login(data.email, data.password), | ||
onSuccess: () => { | ||
router.push("/dashboard"); | ||
}, | ||
onError: (error: ErrorType) => { | ||
console.error("로그인 중 오류 발생:", error); | ||
toast.error("로그인을 실패했습니다. 다시 시도해 주세요."); | ||
}, | ||
}); | ||
|
||
return { signupMutation, loginMutation }; | ||
}; |
File renamed without changes.