Prerequisites
Before you start, you’ll need:- A Resend API key
- A verified domain
- A project with Better Auth installed
Install the Resend SDK
.env
The hook examples below call
void resend.emails.send(...) instead of
awaiting it, as Better Auth
recommends, so the response time
doesn’t reveal whether an account exists. On serverless platforms, wrap the
send in waitUntil (or your platform’s equivalent) so the function doesn’t
terminate before the email is sent.Send password reset and verification emails
Better Auth calls yoursendResetPassword and sendVerificationEmail hooks when a user requests a reset or needs to confirm their address. Send the email with Resend inside each hook.
auth.ts
Set the
from address to match your verified domain.Send magic links (optional)
If you use the magic link plugin, send the sign-in link through thesendMagicLink hook.
auth.ts
Set the
from address to match your verified domain.Send one-time codes (optional)
The email OTP plugin sends a one-time password (OTP), a numeric code, instead of a link. Thetype argument tells you which flow triggered the request so you can tailor the subject line.
auth.ts
Set the
from address to match your verified domain.Customize email templates
For richer, reusable emails, author your templates with React Email and pass the rendered component to Resend’sreact field, or reference a Resend template by id.
auth.ts
Set the
from address to match your verified domain.Debugging email delivery
When a flow doesn’t behave as expected, check both sides:- Better Auth logs show the hook invocation and any errors thrown while sending.
- Resend Logs show the delivery side: accepted, delivered, opened, bounced.