Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/web/src/apis/Auth/postEmailLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a non-credential fallback for transport failures

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 ๐Ÿ‘ย / ๐Ÿ‘Ž.


// ๋กœ๊ทธ์ธ ์‹คํŒจ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ž๊ฒฉ์ฆ๋ช…์„ ๊ณ ์ณ ๊ณง๋ฐ”๋กœ ์žฌ์‹œ๋„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•„
// ๋™์ผ ๋ฉ”์‹œ์ง€ ์–ต์ œ(dedupe)๋ฅผ ๋„๊ณ  ๋งค ์‹œ๋„๋งˆ๋‹ค ํ† ์ŠคํŠธ๋ฅผ ๋…ธ์ถœํ•œ๋‹ค.
showIconToast("logo", message, { dedupe: false });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent duplicate toasts for Enter submissions

When a user submits the login form with Enter, LoginContent.tsx invokes handleSubmit(onSubmit)() in its input onKeyDown handler and then allows the same key event to perform the form's native submit, producing two mutations before isPending can re-render the form. With deduplication explicitly disabled here, both error callbacks now render identical stacked toasts for a single keypress; remove/coalesce the duplicate submission path or otherwise suppress errors from the same user action while still allowing later retries.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

},
});
};

Expand Down
18 changes: 14 additions & 4 deletions apps/web/src/lib/toast/showIconToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ const TOAST_DURATION = 3000;
const TOAST_COOLDOWN = 3500;
const activeToastKeys = new Set<string>();

export const showIconToast = (icon: ToastIconKey, message: string) => {
export type ShowIconToastOptions = {
/** ๋™์ผํ•œ ์•„์ด์ฝ˜+๋ฉ”์‹œ์ง€ ํ† ์ŠคํŠธ๋ฅผ TOAST_COOLDOWN ๋™์•ˆ ์–ต์ œํ• ์ง€ ์—ฌ๋ถ€ (๊ธฐ๋ณธ true) */
dedupe?: boolean;
};

export const showIconToast = (icon: ToastIconKey, message: string, options?: ShowIconToastOptions) => {
const Icon = ICONS[icon];
const key = `${icon}:${message}`;
const dedupe = options?.dedupe ?? true;

if (activeToastKeys.has(key)) return;
activeToastKeys.add(key);
if (dedupe) {
if (activeToastKeys.has(key)) return;
activeToastKeys.add(key);
}

toast.custom(
() => (
Expand All @@ -36,5 +44,7 @@ export const showIconToast = (icon: ToastIconKey, message: string) => {
{ duration: TOAST_DURATION },
);

setTimeout(() => activeToastKeys.delete(key), TOAST_COOLDOWN);
if (dedupe) {
setTimeout(() => activeToastKeys.delete(key), TOAST_COOLDOWN);
}
};
Loading