completionId: cgen-879fd3b7c3424a22a50093fc81296e72

cgen-879fd3b7c3424a22a50093fc81296e72
This commit is contained in:
Builder.io 2025-11-05 04:32:58 +00:00
parent fec30de1e4
commit 694020f2c2

View file

@ -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<string, any>);
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