Skip to main content

Using Resend instead

The default email provider for @lumenize/auth is Cloudflare Email Sending — it's a native Worker binding, no API key, and fits the Cloudflare-first posture of this monorepo. But Cloudflare Email Sending requires the Workers Paid plan, and you may already use Resend elsewhere or want the 100-emails-per-day free tier.

ResendEmailSender is a drop-in alternative that implements the same AuthEmailSenderBase contract. Everything else in the auth package — templates, subjects, the AUTH_EMAIL_SENDER service binding, the from/replyTo/appName settings — is identical.

When to choose Resend

  • You want to stay on the Workers Free plan.
  • Your organization already uses Resend for transactional email.
  • You want Resend's deliverability dashboards or per-message analytics.

Otherwise, the default Cloudflare Email Sending path is simpler.

Setup

1. Create a Resend account and verify your domain

Sign up at resend.com, then verify your sending domain. You'll add DNS records (SPF, DKIM, DMARC) to your domain — Resend's dashboard walks you through it.

2. Generate an API key

Create an API key in the Resend dashboard and add it to your environment:

# Local development (.dev.vars)
RESEND_API_KEY=re_...

# Production
wrangler secret put RESEND_API_KEY

3. Create your AuthEmailSender class

import { ResendEmailSender } from '@lumenize/auth';

export class AuthEmailSender extends ResendEmailSender {
from = 'auth@myapp.com'; // must match your verified Resend domain
// Override templates, subjects, replyTo, or appName here — same as CloudflareEmailSender
}

Export this class from your Worker entry point alongside your other classes. ResendEmailSender handles delivery, default HTML templates, and default subject lines — same as CloudflareEmailSender.

4. Add the service binding to wrangler.jsonc

Unlike the Cloudflare path, there's no send_email binding — Resend is a plain HTTPS API, so the only wiring is the self-referencing service binding that lets the Auth DO reach your entrypoint:

{
"services": [
{
"binding": "AUTH_EMAIL_SENDER",
"service": "your-worker-name", // must match your wrangler.jsonc "name"
"entrypoint": "AuthEmailSender"
}
]
}

Customizing templates

Template and subject overrides work identically to the default path — you just extend ResendEmailSender instead of CloudflareEmailSender. See Customizing Email for the patterns; swap the base class name and everything else applies.

Switching providers later

Moving between providers is a one-line change in your AuthEmailSender class (change the base class) plus the corresponding wrangler.jsonc update — add or remove the send_email binding, add or remove RESEND_API_KEY. No schema migrations, no template rewrites.