Back to Blog

How to Setup Email Verification & Organization Invites with Better Auth and Nodemailer

Royan Gagas
December 27, 2025
Share
tips
product
javascript
react
How to Setup Email Verification & Organization Invites with Better Auth and Nodemailer

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.

Step 1: Installation

First, let's get the necessary packages installed. We need the core auth library and the mailer transport.

Step 2: Setting Up the Email Transporter

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:

Step 3: Configurating the Better Auth Server

Now, we hook everything into Better Auth. We will use two plugins:

1.emailOTP: Handles the logic for generating and validating one-time passwords.
2.organization: Handles team management and intivations tokens.

In your main config file (usually src/lib/auth.ts), inject the Nodemailer functions:

Step 4: Environment Variables

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.

Step 5: Frontend Implementation (Client Side)

Now that the backend is ready, here is how you trigger these actions from your frontend (React Example).

Sign Up (Triggering Verification)

When a user signs up using the emailOTP method, Better Auth will automatically trigger the sendVerificationOTP function we defined earlier.

Sending an Invitation

This is usually done by an Admin inside their dashboard settings.

Accepting an Invitation

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:

Why This Architecture Works

1.Flexibility: By using Nodemailer, you aren't locked into a specific provider. You can start with Gmail for free, then switch to AWS SES or SendGrid as you scale, without changing your auth logic.
2.Full Control: You have 100% control over the HTML templates. You can brand them, style them, and adjust the wording exactly how you want.
3.Security: Your credentials stay on the server. The Client simply request an action (like "invite user"), and the secure server handles the email delivery.

Integrating email verification and invites makes your app feel professional and secure. With Better Auth and Nodemailer, it's surprisingly easy to implement.