pealdevDOCS
Back to peal.dev

AUTH STARTER · EMAIL OTP

Email OTP

Six-digit codes by email for sign-in, verification, and password reset. Same email infrastructure as magic links.

Email OTP is the same idea as magic links, but the user types a 6-digit code instead of clicking a link. Useful when users sign in on a different device than they read email on — and harder to phish.

Turn it on

TypeScript
// src/auth.config.ts
plugins: {
  emailOTP: { enabled: true },
},

Send + verify (client)

TypeScript
// 1. Send the code
await authClient.emailOtp.sendVerificationOtp({
  email,
  type: "sign-in", // or "email-verification" | "forget-password"
});

// 2. User enters the 6-digit code
await authClient.signIn.emailOtp({
  email,
  otp,
});

The three types

  • sign-in — log the user in (no password).
  • email-verification — verify a user's email after sign-up.
  • forget-password — initiate a password reset with a code.

The send function in src/lib/email.ts → sendOTPEmail switches the subject line based on type. Template lives at src/lib/emails/otp-email.tsx.

OTP vs magic link — pick one or both

Some teams ship both — magic link for desktop sign-up, OTP for mobile. Both use the same Resend infrastructure. Both go through the verification table. No extra cost to enable both.