Skip to main content

Overview

createEmailTemplates returns a set of pre-built HTML email templates for every auth flow KavachOS supports. Each template produces a { subject, text, html } object you pass directly to your mail provider.

Setup

import { createEmailTemplates } from 'kavachos';

const templates = createEmailTemplates({
  appName: 'MyApp',
  appUrl: 'https://myapp.com',
  supportEmail: 'support@myapp.com', // optional
});

Built-in templates

TemplateWhen to use
verificationEmail address verification on signup
passwordResetPassword reset request
magicLinkPasswordless login link
emailOtpOne-time passcode for email OTP auth
invitationInvite a user to an organization
welcomePost-signup welcome message

Using a template

Every template is a function that accepts the variables it needs and returns { subject, text, html }.
const { subject, text, html } = templates.magicLink({
  url: 'https://myapp.com/auth/callback?token=abc123',
  expiresInMinutes: 15,
  userEmail: 'alice@example.com',
});

await mailer.send({ to: 'alice@example.com', subject, text, html });

All template signatures

templates.verification({ url: string; userEmail: string });
templates.passwordReset({ url: string; expiresInMinutes: number; userEmail: string });
templates.magicLink({ url: string; expiresInMinutes: number; userEmail: string });
templates.emailOtp({ otp: string; expiresInMinutes: number; userEmail: string });
templates.invitation({ url: string; inviterName: string; orgName: string; userEmail: string });
templates.welcome({ userName: string; userEmail: string });

Integrating with auth plugins

Auth plugins expose callbacks like onSendVerification and onSendMagicLink. Pass template output directly into them.

Customizing templates

Override any template by passing your own function. Custom templates receive the same arguments as built-ins and must return { subject, text, html }.
const templates = createEmailTemplates({
  appName: 'MyApp',
  appUrl: 'https://myapp.com',
  overrides: {
    welcome({ userName, userEmail }) {
      return {
        subject: `Welcome to MyApp, ${userName}`,
        text: `Hey ${userName}, your account (${userEmail}) is ready.`,
        html: `<p>Hey <strong>${userName}</strong>, your account is ready. <a href="https://myapp.com">Get started</a>.</p>`,
      };
    },
  },
});
Overrides only replace the templates you provide. All other templates continue to use the defaults.

Next steps

Magic link

Passwordless auth via email links.

Email OTP

One-time passcodes delivered by email.

Internationalization

Translate email subjects and error messages.
Last modified on April 18, 2026