From 71b4fa2e269eab0cfff09b3134c6e96a849e8da8 Mon Sep 17 00:00:00 2001 From: Nitesh Seram Date: Mon, 28 Jul 2025 09:46:43 +0530 Subject: [PATCH] [web] auth: show auth login redirect error in the screen (#1586) --- .../components/auth/AuthLoginRedirectPage.tsx | 140 ++++++++++++++---- 1 file changed, 114 insertions(+), 26 deletions(-) diff --git a/apps/web/src/components/auth/AuthLoginRedirectPage.tsx b/apps/web/src/components/auth/AuthLoginRedirectPage.tsx index 59fe1bb7b..15b0b96db 100644 --- a/apps/web/src/components/auth/AuthLoginRedirectPage.tsx +++ b/apps/web/src/components/auth/AuthLoginRedirectPage.tsx @@ -1,16 +1,23 @@ 'use client'; +import { useUser } from '@supabase/auth-helpers-react'; import clsx from 'clsx'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; +import { RiEmotionSadLine } from 'react-icons/ri'; +import { useAuthSignInUp } from '~/hooks/user/useAuthFns'; import useAuthFullPageRedirectAfterLogin from '~/hooks/user/useAuthFullPageRedirectAfterLogIn'; import LogoComboMark from '~/components/global/logos/LogoComboMark'; import { useIntl } from '~/components/intl'; +import Button from '~/components/ui/Button'; import Container from '~/components/ui/Container'; import Heading from '~/components/ui/Heading'; import Text from '~/components/ui/Text'; -import { themeRadialWhiteGlowBackground } from '~/components/ui/theme'; +import { + themeRadialWhiteGlowBackground, + themeTextDangerColor, +} from '~/components/ui/theme'; import logEvent from '~/logging/logEvent'; @@ -20,14 +27,39 @@ type Props = Readonly<{ export default function AuthLoginRedirectPage({ next }: Props) { const intl = useIntl(); + const user = useUser(); + const { signInUpHref } = useAuthSignInUp(); useAuthFullPageRedirectAfterLogin(next); + const [errorData, setErrorData] = useState<{ + code?: string; + description?: string; + } | null>(null); + const errorContent = useErrorMessage(); + useEffect(() => { - logEvent('auth.login_success', { - namespace: 'auth', + const hash = window.location.hash.substring(1); + const params = new URLSearchParams(hash); + + const error = params.get('error'); + + if (!error || user) { + logEvent('auth.login_success', { + namespace: 'auth', + }); + + return; + } + + setErrorData({ + code: params.get('error_code') || undefined, + description: params.get('error_description') || undefined, }); - }, []); + }, [user]); + + const { message: errorMessage, name: errorName } = + errorContent[errorData?.code ?? ''] || {}; return (
- -
- - {intl.formatMessage({ - defaultMessage: 'Login successful', - description: 'Title of login successful page', - id: 'OKKVCO', - })} - - - {intl.formatMessage({ - defaultMessage: 'Redirecting you...', - description: 'Auth redirect message', - id: 'RJMyW6', - })} - -
+ {errorData && !user ? ( +
+ + + {errorName || + intl.formatMessage({ + defaultMessage: 'An error has occurred', + description: 'Error message title', + id: 'jCB415', + })} + + + {errorMessage || errorData.description} + +
+ ) : ( + <> + +
+ + {intl.formatMessage({ + defaultMessage: 'Login successful', + description: 'Title of login successful page', + id: 'OKKVCO', + })} + + + {intl.formatMessage({ + defaultMessage: 'Redirecting you...', + description: 'Auth redirect message', + id: 'RJMyW6', + })} + +
+ + )}
); } + +function useErrorMessage(): Record { + const intl = useIntl(); + + return { + otp_expired: { + message: intl.formatMessage({ + defaultMessage: + 'OTP code for this sign-in has expired. Please try to sign in again.', + description: 'Error message for expired OTP', + id: '27QHDj', + }), + name: intl.formatMessage({ + defaultMessage: 'OTP expired', + description: 'Error name for expired OTP', + id: '/JwmN3', + }), + }, + }; +}