From ecaa24c0f62f1ab3ea45e7d509ae39c19a724beb Mon Sep 17 00:00:00 2001 From: isra el Date: Mon, 20 Jan 2025 18:23:04 +0300 Subject: [PATCH] chore(web): redirect to email verification page after signup --- .../(auth)/(components)/register-form.tsx | 2 +- web/app/(app)/(auth)/verify-email/page.tsx | 87 ++++++++++++++++++- web/config/routes.ts | 1 + 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/web/app/(app)/(auth)/(components)/register-form.tsx b/web/app/(app)/(auth)/(components)/register-form.tsx index 7f7ca63..4c6e1e5 100644 --- a/web/app/(app)/(auth)/(components)/register-form.tsx +++ b/web/app/(app)/(auth)/(components)/register-form.tsx @@ -67,7 +67,7 @@ export default function RegisterForm() { message: 'Failed to create account', }) } else { - router.push(Routes.dashboard) + router.push(`${Routes.verifyEmail}?verificationEmailSent=1`) } } catch (error) { console.error('register error:', error) diff --git a/web/app/(app)/(auth)/verify-email/page.tsx b/web/app/(app)/(auth)/verify-email/page.tsx index c1ba3eb..841642e 100644 --- a/web/app/(app)/(auth)/verify-email/page.tsx +++ b/web/app/(app)/(auth)/verify-email/page.tsx @@ -17,6 +17,7 @@ import { Loader2, CheckCircle, XCircle, Mail, ArrowRight } from 'lucide-react' import { useMutation } from '@tanstack/react-query' import httpBrowserClient from '@/lib/httpBrowserClient' import { ApiEndpoints } from '@/config/api' +import { Routes } from '@/config/routes' const ErrorAlert = ({ message }: { message: string }) => ( Success - {successMessage} + +
+
{successMessage}
+ + Go to Dashboard + +
+
) if (error) return @@ -185,15 +193,92 @@ const VerifyEmail = ({ ) } +const CheckEmailPrompt = () => { + const { + mutate: sendVerificationEmailMutation, + isPending, + isError, + isSuccess, + } = useMutation({ + mutationFn: () => + httpBrowserClient.post( + ApiEndpoints.auth.sendEmailVerificationEmail(), + {} + ), + }) + + return ( + + + Check your email + + We've sent you a verification email. Please check your inbox and click + the link to verify your account. + + + + {isSuccess && ( + + + + Email Sent + + + A new verification email has been sent to your inbox + + + )} + {isError && ( + + + Error + + Failed to resend verification email + + + )} + + +
+ + Didn't receive the email? + + +
+
+
+ ) +} + export default function VerifyEmailPage() { const searchParams = useSearchParams() const userId = searchParams.get('userId') const verificationCode = searchParams.get('verificationCode') + const verificationEmailSent = searchParams.get('verificationEmailSent') return (
{userId && verificationCode ? ( + ) : verificationEmailSent ? ( + ) : ( )} diff --git a/web/config/routes.ts b/web/config/routes.ts index b55c12b..c0a52de 100644 --- a/web/config/routes.ts +++ b/web/config/routes.ts @@ -5,6 +5,7 @@ export const Routes = { register: '/register', logout: '/logout', resetPassword: '/reset-password', + verifyEmail: '/verify-email', dashboard: '/dashboard',