better-auth-emails
v0.2.1
Published
A lightweight (< 1.5KB gzipped), customizable email plugin for Better Auth with pre-compiled templates and theme support
Maintainers
Readme
Better Auth Emails
A lightweight, framework-agnostic email plugin for Better Auth with pre-compiled templates and strict type support.
From the creator of simpleemailapi.dev - The developer-first email API.
Features
- 🚀 Simple API - Configure once, use everywhere with direct passthrough
- 📧 All Email Types - Verification, Password Reset, Magic Link, OTP
- 🎨 Theming - Built-in themes with complete layouts (not just colors)
- 🏗️ Zero Runtime - < 1.5KB gzipped main bundle, with lazy-loaded themes (~2KB gzipped each)
- 🔒 Type-safe - Strict TypeScript types for customization
Installation
npm install better-auth-emails simpleemailapiQuick Start
Here is a very simple example of how to use it with Next.js and SimpleEmailAPI.
import { betterAuth } from 'better-auth';
import { createEmails } from 'better-auth-emails';
import Database from 'better-sqlite3';
const db = new Database('local.sqlite');
// 1. Configure emails once
export const emails = createEmails({
provider: 'simpleemailapi',
apiKey: process.env.SIMPLE_EMAIL_API_KEY!,
from: '[email protected]',
appName: 'Next.js Example',
theme: "classic",
colors: {
brandColor: "#252525",
buttonText: "#fdfdfd",
backgroundColor: "#dad9d9",
textColor: "#000000",
secondaryBackground: "#252525",
secondaryTextColor: "#fdfdfd",
borderColor: "#252525",
}
});
// 2. Use with Better Auth - direct passthrough!
export const auth = betterAuth({
database: db,
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: emails.sendResetPassword, // Pass directly inside emailAndPassword
},
// Direct passthrough - no wrappers needed!
emailVerification: {
sendVerificationEmail: emails.sendVerificationEmail,
},
// Plugins works too!
// plugins: [
// magicLink({ sendMagicLink: emails.sendMagicLink }),
// emailOTP({ sendVerificationOTP: emails.sendOTP }),
// ],
});Themes
License
MIT
