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 resetPasswordEmailLocalization = { RESET_YOUR_PASSWORD: "Reset your password", LOGO: "Logo", WE_RECEIVED_REQUEST_TO_RESET_PASSWORD: "We received a request to reset the password for your {appName} account {email}.", RESET_PASSWORD: "Reset password", 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_PASSWORD_RESET: "If you didn't request a password reset, you can safely ignore this email. Your password will remain unchanged.", POWERED_BY_BETTER_AUTH: "Powered by {betterAuth}" } /** * Localization strings for the ResetPasswordEmail component. * * Contains all text content used in the password reset email template. */ export type ResetPasswordEmailLocalization = typeof resetPasswordEmailLocalization /** * Props for the ResetPasswordEmail component. */ export interface ResetPasswordEmailProps { /** Password reset URL that users must click to reset their password */ url: string /** Email address of the user requesting password reset */ email?: string /** Name of the application sending the email */ appName?: string /** Number of minutes until the reset 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 `ResetPasswordEmailLocalization` */ localization?: Partial } /** * Email template component that sends password reset links to users. * * This email includes: * - Password reset 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 ResetPasswordEmail = ({ url, email, appName, expirationMinutes = 60, logoURL, colors, classNames, darkMode = true, poweredBy, head, ...props }: ResetPasswordEmailProps) => { const localization = { ...ResetPasswordEmail.localization, ...props.localization } const previewText = localization.RESET_YOUR_PASSWORD return ( {head} {previewText}
{logoURL && (typeof logoURL === "string" ? ( {appName ) : ( <> {appName {appName ))} {localization.RESET_YOUR_PASSWORD} {(() => { const textWithAppName = localization.WE_RECEIVED_REQUEST_TO_RESET_PASSWORD.replace( "{appName}", appName || "" ) .replace(/\s{2,}/g, " ") .replace(" .", ".") const [beforeEmail, afterEmail] = textWithAppName.split("{email}") return email ? ( <> {beforeEmail} {email} {afterEmail} ) : ( textWithAppName .replace("{email}", "") .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_PASSWORD_RESET} {poweredBy && ( {(() => { const [beforeBetterAuth, afterBetterAuth] = localization.POWERED_BY_BETTER_AUTH.split("{betterAuth}") return ( <> {beforeBetterAuth} better-auth {afterBetterAuth} ) })()} )}
) } ResetPasswordEmail.localization = resetPasswordEmailLocalization ResetPasswordEmail.PreviewProps = { url: "https://better-auth-ui.com/auth/reset-password?token=example-token", email: "m@example.com", appName: "Better Auth", darkMode: true } as ResetPasswordEmailProps export default ResetPasswordEmail