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 emailChangedEmailLocalization = { YOUR_EMAIL_ADDRESS_HAS_BEEN_CHANGED: "Your email address has been changed", LOGO: "Logo", EMAIL_ADDRESS_CHANGED: "Email address changed", EMAIL_ADDRESS_FOR_YOUR_ACCOUNT_CHANGED: "The email address for your {appName} account has been changed.", PREVIOUS_EMAIL: "Previous email:", NEW_EMAIL: "New email:", IF_YOU_MADE_THIS_CHANGE: "If you made this change, you can safely ignore this email.", I_DIDNT_MAKE_THIS_CHANGE: "I didn't make this change", EMAIL_SENT_BY: "Email sent by {appName}.", IF_YOU_DIDNT_AUTHORIZE_THIS_CHANGE: "If you didn't authorize this change, please contact support immediately {supportEmail} to secure your account.", POWERED_BY_BETTER_AUTH: "Powered by {betterAuth}" } /** * Localization strings for the EmailChangedEmail component. * * Contains all text content used in the email changed notification email template. */ export type EmailChangedEmailLocalization = typeof emailChangedEmailLocalization /** * Props for the EmailChangedEmail component. */ export interface EmailChangedEmailProps { /** The previous email address that was changed */ oldEmail?: string /** The new email address */ newEmail?: string /** URL to revert the email change if unauthorized */ revertURL?: string /** Name of the application sending the email */ appName?: string /** Support email address for security concerns */ supportEmail?: string /** 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 `EmailChangedEmailLocalization` */ localization?: Partial } /** * Email template component that notifies users when their email address has been changed. * * This email includes: * - Display of both old and new email addresses * - Revert action button if unauthorized change occurred * - Security information and support contact details * - Customizable branding and styling * - Support for light/dark mode themes * * @example * ```tsx * * ``` */ export const EmailChangedEmail = ({ oldEmail, newEmail, revertURL, appName, supportEmail, logoURL, colors, classNames, darkMode = true, poweredBy, head, ...props }: EmailChangedEmailProps) => { const localization = { ...EmailChangedEmail.localization, ...props.localization } const previewText = localization.YOUR_EMAIL_ADDRESS_HAS_BEEN_CHANGED return ( {head} {previewText}
{logoURL && (typeof logoURL === "string" ? ( {appName ) : ( <> {appName {appName ))} {localization.EMAIL_ADDRESS_CHANGED} {localization.EMAIL_ADDRESS_FOR_YOUR_ACCOUNT_CHANGED.replace( "{appName}", appName || "" ) .replace(/\s{2,}/g, " ") .replace(" .", ".")} {(oldEmail || newEmail) && (
{oldEmail && ( <> {localization.PREVIOUS_EMAIL} {oldEmail} )} {newEmail && ( <> {localization.NEW_EMAIL} {newEmail} )}
)} {localization.IF_YOU_MADE_THIS_CHANGE} {revertURL && (
)}
{appName && ( {localization.EMAIL_SENT_BY.replace("{appName}", appName)} )} {(() => { const [beforeSupportEmail, afterSupportEmail] = localization.IF_YOU_DIDNT_AUTHORIZE_THIS_CHANGE.split( "{supportEmail}" ) return supportEmail ? ( <> {beforeSupportEmail} {supportEmail} {afterSupportEmail} ) : ( localization.IF_YOU_DIDNT_AUTHORIZE_THIS_CHANGE.replace( "{supportEmail}", "" ) .replace(/\s{2,}/g, " ") .replace(" .", ".") ) })()} {poweredBy && ( {(() => { const [beforeBetterAuth, afterBetterAuth] = localization.POWERED_BY_BETTER_AUTH.split("{betterAuth}") return ( <> {beforeBetterAuth} better-auth {afterBetterAuth} ) })()} )}
) } EmailChangedEmail.localization = emailChangedEmailLocalization EmailChangedEmail.PreviewProps = { oldEmail: "old@example.com", newEmail: "new@example.com", supportEmail: "support@example.com", revertURL: "https://better-auth-ui.com/auth/revert-email?token=example-token", appName: "Better Auth", poweredBy: true, darkMode: true } as EmailChangedEmailProps export default EmailChangedEmail