
Authentication today goes beyond just "username and password." To build a secure and collaborative application, you almost cretainly need two things: Email Verification (to ensure users are real) and Organization Invites (to let users collaborate).
Better Auth is fantastic because it's modular. Instead of forcing a specific email provider on you, it provides the logic and lets you handle the delivery.
In this guide, we will implement OTP Verification and Team Invitations using Better Auth and Nodemailer. We chose Nodemailer because it gives you total freedom, you can use Gmail, AWS SES, Resend, or any SMTP server you want.
First, let's get the necessary packages installed. We need the core auth library and the mailer transport.
Before touching the auth logic, we need a helper file to handle the actual sending of emails. We will create a transporter (the postman) and defining our HTML templates (the letters).
Create a file at src/lib/email.ts:
Now, we hook everything into Better Auth. We will use two plugins:
emailOTP: Handles the logic for generating and validating one-time passwords.organization: Handles team management and intivations tokens.In your main config file (usually src/lib/auth.ts), inject the Nodemailer functions:
Security is key. Never hardcode your SMTP credentials. Set these up in your .env file.
Pro Tip: For local development, use a service like Mailtrap or Ethereal to catch emails without spamming real users.
Now that the backend is ready, here is how you trigger these actions from your frontend (React Example).
When a user signs up using the emailOTP method, Better Auth will automatically trigger the sendVerificationOTP function we defined earlier.
This is usually done by an Admin inside their dashboard settings.
When the user clicks the link in their email (e.g., http://localhost:3000/accept-invitation/invitation-id-123), you handle it on this page:
Integrating email verification and invites makes your app feel professional and secure. With Better Auth and Nodemailer, it's surprisingly easy to implement.