import { Body, Button, Container, Head, Heading, Hr, Html, Img, Link, Preview, pixelBasedPreset, Section, Tailwind, Text } from "@react-email/components" import type { ReactNode } from "react" import { cn } from "../../../lib/utils" import { type EmailClassNames, type EmailColors, EmailStyles } from "./email-styles" const emailVerificationEmailLocalization = { VERIFY_YOUR_EMAIL_ADDRESS: "Verify your email address", LOGO: "Logo", CLICK_BUTTON_TO_VERIFY_EMAIL: "Click the button below to verify your email address {emailAddress} for your {appName} account.", VERIFY_EMAIL_ADDRESS: "Verify email address", OR_COPY_AND_PASTE_URL: "Or copy and paste this URL into your browser:", THIS_LINK_EXPIRES_IN_MINUTES: "This link expires in {expirationMinutes} minutes.", EMAIL_SENT_BY: "Email sent by {appName}.", IF_YOU_DIDNT_REQUEST_THIS_EMAIL: "If you didn't request this email, you can safely ignore it. Someone else might have typed your email address by mistake.", POWERED_BY_BETTER_AUTH: "Powered by {betterAuth}" } /** * Localization strings for the EmailVerificationEmail component. * * Contains all text content used in the email verification email template. */ export type EmailVerificationEmailLocalization = typeof emailVerificationEmailLocalization /** * Props for the EmailVerificationEmail component. */ export interface EmailVerificationEmailProps { /** Verification URL that users must click to verify their email */ url: string /** Email address being verified */ email?: string /** Name of the application sending the email */ appName?: string /** Number of minutes until the verification link expires */ expirationMinutes?: number /** Logo URL(s) - a single string or light/dark variants. If omitted, no logo is shown. */ logoURL?: string | { light: string; dark: string } /** Custom CSS class names for styling specific parts of the email */ classNames?: EmailClassNames /** Custom color scheme for light and dark modes */ colors?: EmailColors /** Whether to show the "Powered by better-auth" footer */ poweredBy?: boolean /** Whether to enable dark mode support */ darkMode?: boolean /** Additional React nodes to inject into the email head */ head?: ReactNode /** * Localization overrides for customizing email text * @remarks `EmailVerificationEmailLocalization` */ localization?: Partial } /** * Email template component that sends email verification links to users. * * This email includes: * - Verification button and fallback URL * - Expiration time information * - Security notice for unauthorized requests * - Customizable branding and styling * - Support for light/dark mode themes * * @example * ```tsx * * ``` */ export const EmailVerificationEmail = ({ url, email, appName, expirationMinutes = 60, logoURL, colors, classNames, darkMode = true, poweredBy, head, ...props }: EmailVerificationEmailProps) => { const localization = { ...EmailVerificationEmail.localization, ...props.localization } const previewText = localization.VERIFY_YOUR_EMAIL_ADDRESS return ( {head} {previewText}
{logoURL && (typeof logoURL === "string" ? ( {appName ) : ( <> {appName {appName ))} {localization.VERIFY_EMAIL_ADDRESS} {(() => { const textWithAppName = localization.CLICK_BUTTON_TO_VERIFY_EMAIL.replace( "{appName}", appName || "" ) .replace(/\s{2,}/g, " ") .replace(" .", ".") const [beforeEmailAddress, afterEmailAddress] = textWithAppName.split("{emailAddress}") return email ? ( <> {beforeEmailAddress} {email} {afterEmailAddress} ) : ( textWithAppName .replace("{emailAddress}", "") .replace(/\s{2,}/g, " ") .replace(" .", ".") ) })()}
{localization.OR_COPY_AND_PASTE_URL} {url}
{expirationMinutes || appName ? ( {expirationMinutes ? localization.THIS_LINK_EXPIRES_IN_MINUTES.replace( "{expirationMinutes}", expirationMinutes.toString() ) : null} {appName && ( <> {expirationMinutes ? " " : ""} {localization.EMAIL_SENT_BY.replace("{appName}", appName)} )} ) : null} {localization.IF_YOU_DIDNT_REQUEST_THIS_EMAIL} {poweredBy && ( {(() => { const [beforeBetterAuth, afterBetterAuth] = localization.POWERED_BY_BETTER_AUTH.split("{betterAuth}") return ( <> {beforeBetterAuth} better-auth {afterBetterAuth} ) })()} )}
) } /** * Default localization strings for the email verification template. * Can be overridden via the `localization` prop. */ EmailVerificationEmail.localization = emailVerificationEmailLocalization /** * Example props for previewing the email template in development. */ EmailVerificationEmail.PreviewProps = { url: "https://better-auth-ui.com/auth/verify-email?token=example-token", appName: "Better Auth", email: "m@example.com", darkMode: true } as EmailVerificationEmailProps export default EmailVerificationEmail