Better Auth
Send Better Auth transactional email through Samva with @samva/better-auth.
Better Auth
Use @samva/better-auth
to send Better Auth email callbacks through Samva. The package provides callback
fragments for manual wiring and a withSamva() helper for the common setup.
Better Auth owns authentication. Samva sends the rendered email over your
verified sender, so there is no from option in the integration.
Install
bun add better-auth samva @samva/better-authWire the common callbacks
import { betterAuth } from "better-auth";
import { withSamva } from "@samva/better-auth";
export const auth = betterAuth(
withSamva(
{
emailAndPassword: {
enabled: true,
},
},
{
apiKey: process.env.SAMVA_API_KEY!,
plugins: {
emailOTP: true,
magicLink: true,
},
},
),
);withSamva() fills missing email verification and password reset callbacks. It
also fills change-email and delete-account callbacks when those Better Auth user
flows are already enabled. Existing callbacks are preserved.
Manual wiring
Use samvaEmail() when you want to control each Better Auth option yourself:
import { betterAuth } from "better-auth";
import { emailOTP, magicLink } from "better-auth/plugins";
import { samvaEmail } from "@samva/better-auth";
const samva = samvaEmail({ apiKey: process.env.SAMVA_API_KEY! });
export const auth = betterAuth({
emailVerification: samva.emailVerification,
emailAndPassword: {
enabled: true,
sendResetPassword: samva.emailAndPassword.sendResetPassword,
},
plugins: [
emailOTP(samva.plugins.emailOTP),
magicLink(samva.plugins.magicLink),
],
});Covered triggers
The package includes defaults for:
- email verification
- password reset
- change-email confirmation
- delete-account confirmation
- email OTP
- two-factor OTP
- magic links
- organization invitations
Override any template with a function returning HTML, { subject, html, text },
or a React Email element. React Email rendering is optional and uses
@react-email/render when your template returns an element.