From f5f0bb8c5873733d1422669470065dbfaa162681 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Thu, 19 Feb 2026 17:17:23 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20ux:=20handle=20duplicate=20email?= =?UTF-8?q?=20account=20error=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/submitProviderCallback.ts | 10 ++++++++-- features/authCallback/index.tsx | 12 +++++++----- .../widgets/signin/components/SignInCard.tsx | 18 ++++++++++++++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/features/authCallback/actions/submitProviderCallback.ts b/features/authCallback/actions/submitProviderCallback.ts index 8afb005..965af22 100644 --- a/features/authCallback/actions/submitProviderCallback.ts +++ b/features/authCallback/actions/submitProviderCallback.ts @@ -32,7 +32,12 @@ export const submitProviderCallback = async ( }>; if (!responseProvision.success) - throw new Error("Failed to submit provider callback"); + return { + success: false, + status: responseProvision.status, + message: responseProvision.message, + error: responseProvision.error, + }; (await cookies()).set({ name: "auth_token", @@ -48,7 +53,8 @@ export const submitProviderCallback = async ( return { success: false, status: 500, - message: "Error submitting provider callback", + message: + "Connection to authentication service failed. Please try again later.", error: error, }; } diff --git a/features/authCallback/index.tsx b/features/authCallback/index.tsx index 3cab339..602753b 100644 --- a/features/authCallback/index.tsx +++ b/features/authCallback/index.tsx @@ -11,10 +11,13 @@ const AuthCallbackIndex = () => { "We are processing your authentication.", ); - const finishOAuthFlow = (type: string) => { + const finishOAuthFlow = (type: string, message?: string) => { setTimeout(() => { if (!window.opener) window.location.href = "/"; - window.opener.postMessage({ type: type }, window.location.origin); + window.opener.postMessage( + { type: type, message: message }, + window.location.origin, + ); window.close(); }, 1000); }; @@ -24,11 +27,10 @@ const AuthCallbackIndex = () => { const response = await submitProviderCallback(name as string, queries); if (response.success) { setTextDescription("Authentication successful! Redirecting..."); - finishOAuthFlow("oauth-success"); + finishOAuthFlow("oauth-success", response.message); } else { - console.error("Error in authentication callback:", response); setTextDescription("Authentication failed. Please try again."); - finishOAuthFlow("oauth-failed"); + finishOAuthFlow("oauth-failed", response.message); } })(); }, [name, queries]); diff --git a/shared/widgets/signin/components/SignInCard.tsx b/shared/widgets/signin/components/SignInCard.tsx index 50f228c..e308102 100644 --- a/shared/widgets/signin/components/SignInCard.tsx +++ b/shared/widgets/signin/components/SignInCard.tsx @@ -18,6 +18,7 @@ import { import { Icon } from "@iconify/react"; import { Spinner } from "@/shared/libs/shadcn/ui/spinner"; import { getOauthEndpoint } from "../actions/getOauthEndpoint"; +import { toast } from "sonner"; const SignInCard = () => { const [isLoading, setIsLoading] = useState(false); @@ -49,8 +50,21 @@ const SignInCard = () => { // Handle the feedback from popup window for OAuth const handleMessage = useCallback((event: MessageEvent) => { if (event.origin !== window.location.origin) return; - if (event.data.type === "oauth-success") window.location.reload(); - if (event.data.type === "oauth-failed") setIsLoading(false); + if (event.data.type === "oauth-success") { + toast.success("Authentication successful! Redirecting...", { + description: event.data.message, + richColors: true, + }); + window.location.reload(); + } + if (event.data.type === "oauth-failed") { + toast.error("Authentication failed.", { + description: event.data.message || "Please try again.", + duration: 5000, + richColors: true, + }); + setIsLoading(false); + } }, []); useEffect(() => {