-
Notifications
You must be signed in to change notification settings - Fork 3
๐ ์ด๋ฉ์ผ ๋ก๊ทธ์ธ ์คํจ ์ ํ ์คํธ๊ฐ ํ์๋์ง ์๋ ๋ฌธ์ ์์ #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,20 +2,30 @@ import { useMutation } from "@tanstack/react-query"; | |
|
|
||
| import type { AxiosError } from "axios"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { SKIP_GLOBAL_ERROR_TOAST_META } from "@/lib/react-query/errorToastMeta"; | ||
| import { showIconToast } from "@/lib/toast/showIconToast"; | ||
| import useAuthStore from "@/lib/zustand/useAuthStore"; | ||
| import { getCommunityRedirectOrFallback } from "@/utils/authRedirect"; | ||
| import { type AuthRedirectOptions, authApi, type EmailLoginRequest, type EmailLoginResponse } from "./api"; | ||
|
|
||
| const EMAIL_LOGIN_FAILURE_MESSAGE = "์ด๋ฉ์ผ ๋๋ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์."; | ||
|
|
||
| type EmailLoginErrorResponse = { | ||
| message?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * @description ์ด๋ฉ์ผ ๋ก๊ทธ์ธ์ ์ํ useMutation ์ปค์คํ ํ | ||
| */ | ||
| const usePostEmailAuth = ({ redirectPath }: AuthRedirectOptions = {}) => { | ||
| const { setAccessToken } = useAuthStore(); | ||
| const router = useRouter(); | ||
|
|
||
| return useMutation<EmailLoginResponse, AxiosError, EmailLoginRequest>({ | ||
| return useMutation<EmailLoginResponse, AxiosError<EmailLoginErrorResponse>, EmailLoginRequest>({ | ||
| mutationFn: (data) => authApi.postEmailLogin(data), | ||
| // ๋ก๊ทธ์ธ API๋ publicAxiosInstance๋ฅผ ์ฌ์ฉํด ์ ์ญ 401 ์ธํฐ์ ํฐ/ํ ์คํธ๊ฐ ์ ์ฉ๋์ง ์์ผ๋ฏ๋ก | ||
| // ์ ์ญ ์๋ฌ ํ ์คํธ๋ฅผ ๊ฑด๋๋ฐ๊ณ ์ด mutation์์ ์ง์ ์ฒ๋ฆฌํ๋ค. | ||
| meta: SKIP_GLOBAL_ERROR_TOAST_META, | ||
| onSuccess: (data) => { | ||
| const { accessToken } = data; | ||
|
|
||
|
|
@@ -31,6 +41,13 @@ const usePostEmailAuth = ({ redirectPath }: AuthRedirectOptions = {}) => { | |
| router.push(getCommunityRedirectOrFallback(redirectPath)); | ||
| }, 100); | ||
| }, | ||
| onError: (error) => { | ||
| const message = error.response?.data?.message || EMAIL_LOGIN_FAILURE_MESSAGE; | ||
|
|
||
| // ๋ก๊ทธ์ธ ์คํจ๋ ์ฌ์ฉ์๊ฐ ์๊ฒฉ์ฆ๋ช ์ ๊ณ ์ณ ๊ณง๋ฐ๋ก ์ฌ์๋ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ | ||
| // ๋์ผ ๋ฉ์์ง ์ต์ (dedupe)๋ฅผ ๋๊ณ ๋งค ์๋๋ง๋ค ํ ์คํธ๋ฅผ ๋ ธ์ถํ๋ค. | ||
| showIconToast("logo", message, { dedupe: false }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a user submits the login form with Enter, Useful? React with ๐ย / ๐. |
||
| }, | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the request fails without a response or response messageโfor example while offline, on timeout, or because of a CORS failureโthis always tells the user to check their credentials. The new mutation metadata also suppresses the global handler, which previously surfaced the Axios error message for these non-401 failures, so users now receive misleading recovery guidance; reserve the credential fallback for authentication responses and retain a connectivity/general fallback for other failures.
Useful? React with ๐ย / ๐.