-
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.
- 회원가입 폼에서 서비스 코드 분리 - tanstack query(react-query)를 사용하여 회원가입 로직 통합 - 코드 전반에 걸쳐 가독성 및 유지 보수성 향상
- Loading branch information
Showing
4 changed files
with
62 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import api from "@/lib/api"; | ||
|
||
export const signup = async (data: { email: string; nickname: string; password: string }) => { | ||
const response = await api.post("/user", { | ||
email: data.email, | ||
name: data.nickname, | ||
password: data.password, | ||
}); | ||
return response.data; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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"; | ||
|
||
export const useSignup = () => { | ||
const router = useRouter(); | ||
console.log("1"); | ||
|
||
return useMutation({ | ||
mutationFn: signup, | ||
onSuccess: () => { | ||
toast.success("회원가입이 완료되었습니다."); | ||
router.push("/login"); | ||
}, | ||
onError: (error: ErrorType) => { | ||
throw error; | ||
}, | ||
}); | ||
}; |