diff --git a/client/components/onboarding/Welcome.tsx b/client/components/onboarding/Welcome.tsx index d240bc24..0473fa71 100644 --- a/client/components/onboarding/Welcome.tsx +++ b/client/components/onboarding/Welcome.tsx @@ -70,113 +70,6 @@ export default function Welcome({ } }, [user]); - const handleResendVerification = async () => { - if (!emailAddress) { - toastError({ - title: "Email unavailable", - description: "We couldn't determine which email to verify.", - }); - return; - } - - setIsSendingVerification(true); - setFallbackVerificationLink(null); - - try { - // First try Supabase to send via your configured SMTP - const { error: resendError } = await supabase.auth.resend({ - type: "signup", - email: emailAddress, - } as any); - - if (!resendError) { - toastSuccess({ - title: "Verification email sent", - description: `We sent a confirmation message to ${emailAddress}.`, - }); - return; - } - - // Fallback to server-generated link (and optional Resend delivery) - const redirectTo = - typeof window !== "undefined" - ? `${window.location.origin}/login?verified=1` - : undefined; - - const response = await fetch("/api/auth/send-verification-email", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - email: emailAddress, - redirectTo, - fullName: fullNameValue, - }), - }); - - const payload = await response - .json() - .catch(() => ({}) as Record); - - if (!response.ok) { - const manualLink = - typeof payload?.verificationUrl === "string" - ? payload.verificationUrl - : null; - - if (manualLink) { - setFallbackVerificationLink(manualLink); - toastWarning({ - title: payload?.message || "Partial failure", - description: - (payload?.error as string) || - "We couldn't send the email automatically; use the manual link below.", - }); - } else { - toastError({ - title: "Verification email failed", - description: - payload?.error || - payload?.message || - "Failed to send verification email", - }); - } - return; - } - - const sent = Boolean(payload?.sent); - const manualLink = - typeof payload?.verificationUrl === "string" - ? payload.verificationUrl - : null; - - if (sent) { - toastSuccess({ - title: "Verification email sent", - description: `We sent a confirmation message to ${emailAddress}.`, - }); - } else { - toastWarning({ - title: "Email service unavailable", - description: - payload?.message || - "We couldn't send the verification email automatically. Use the manual link below.", - }); - } - - if (manualLink && !sent) { - setFallbackVerificationLink(manualLink); - } - } catch (error: any) { - console.error("Resend verification failed", error); - toastError({ - title: "Verification email failed", - description: - error?.message || "Unable to send verification email right now.", - }); - } finally { - setIsSendingVerification(false); - } - }; const handleCheckVerification = async () => { setIsCheckingVerification(true); @@ -299,31 +192,6 @@ export default function Welcome({ } }; - const autoResendTriggeredRef = useRef(false); - useEffect(() => { - if (typeof window === "undefined") return; - if (!emailAddress) return; - if (isVerified) return; - if (autoResendTriggeredRef.current) return; - - const key = `auto_resend_v1:${String(emailAddress).toLowerCase()}`; - try { - if (window.localStorage.getItem(key) === "1") return; - autoResendTriggeredRef.current = true; - window.localStorage.setItem(key, "1"); - // Fire-and-forget; handler manages its own toasts/states - handleResendVerification().catch(() => { - /* ignore */ - }); - } catch { - if (!autoResendTriggeredRef.current) { - autoResendTriggeredRef.current = true; - handleResendVerification().catch(() => { - /* ignore */ - }); - } - } - }, [emailAddress, isVerified]); const VerificationIcon = isVerified ? MailCheck : MailWarning; const verificationBorderClass = isVerified