@kaaarel/auth
Docs: E-mails
View .md

E-mails

import { resend } from "@kaaarel/auth";

email: {
  from: "Leads <no-reply@leads.example>",
  send: resend(process.env.RESEND_API_KEY),
  templates: { /* optional overrides */ },
}
  • send(message) gets { from, to, subject, html, text }. Write your own for any provider.
  • resend(apiKey) calls the Resend HTTP API with fetch.
  • Without email, e-mails print to the console outside production. In production, a missing email is an error when the package needs to send one.
  • E-mails go out in the background, after the function has answered. So the answer time does not show whether an account exists. Send errors are logged with console.error. In tests, await auth.settled() waits for them.

When the package sends e-mails

Template Sent when Link
verifyEmail Sign-up, and sign-in before verification /auth/verify?token= (24 hours)
accountExists Sign-up with an e-mail that has an account pages.signIn
resetPassword requestReset pages.resetPassword?token= (1 hour)
passwordChanged changePassword none
changeEmail changeEmail, to the new address /auth/verify?token= (24 hours)
emailChanged The new address was confirmed, to the old address none
accountLinked Google or GitHub was linked to the user none
tokenCreated An API token was created none
invite workspaces.invite pages.acceptInvite?token= (7 days)

Your own templates

Each template gets data and returns { subject, html, text }:

templates: {
  resetPassword: ({ appName, url, email, name }) => ({
    subject: `Uus parool – ${appName}`,
    html: `<p>Tere${name ? `, ${name}` : ""}!</p><p><a href="${url}">Vali uus parool</a></p>`,
    text: `Vali uus parool: ${url}`,
  }),
},
Template Data
all appName, url, email, name
emailChanged also newEmail
passwordChanged no url
accountLinked also provider ("Google", "GitHub"); no url
tokenCreated also tokenName; no url
invite also workspace, invitedBy, role

Escape values you put into HTML. The default templates do. Keep user-written text (workspace names, user names) out of the subject line: the default invite subject has only the app name.