Supports email/password, Google/GitHub/Slack OAuth, magic links, email OTP, TOTP two-factor authentication, and anonymous login
next-convex-betterauth-template — Next.js Starter Template
By podalls97
A full-stack authentication template based on Next.js, Convex, and Better Auth, with built-in email/password, OAuth, magic links, email OTP, TOTP two-factor authentication, and anonymous login, plus protected routes, email templates, documentation, and API reference pages.
Explore the design
Compare the page layouts and mobile experience. Open any screenshot for a closer look.
Actual screenshot captured by the server browser.
All pages & views 2
Screenshots show visual appearance; interactive behavior may differ.
What stands out
A quick read of the recorded project description.
Built-in protected routes, email verification, and password reset flows
Uses Convex as the real-time database, with schema and authentication logic centralized in the convex directory
Provides React Email templates and a responsive dark mode interface
Includes /documentation and /api-reference pages plus CLAUDE.md technical documentation
Template Details
This is a full-stack starter template for authentication scenarios, combining a Next.js frontend, Convex real-time database, and the Better Auth authentication layer. The repository provides ready-to-run signup, login, email verification, password reset, two-factor authentication (TOTP, including QR codes and backup codes), magic link, email OTP, and anonymous login flows, along with a dark mode interface and React Email templates.
The template includes a protected route mechanism (described in the README as the Next.js 16 proxy pattern), built-in /documentation and /api-reference pages, and a CLAUDE.md for AI coding assistants. The project structure separates (auth) and (unauth) route groups, with authentication logic centralized in convex/auth.ts and src/lib/auth.ts, and the database schema in convex/schema.ts.
Before use, you need to prepare your own Convex deployment, Better Auth secret, email service (Resend or SMTP), and optional Google, GitHub, and Slack OAuth credentials, and set variables separately in .env.local and the Convex environment. The repository is MIT licensed; the free scope is limited to this version of the code, and external services and third-party assets must be checked separately.
Is it right for your project?
Use Cases
- Quickly building an authentication layer for a Next.js app with multiple login methods
- Using Convex as a real-time database and managing user data in a unified way
- Projects that need complete account flows such as email verification, password reset, and two-factor authentication
- Preparing a codebase with CLAUDE.md and API references for AI coding assistants
Suitable For
- Full-stack developers using the Next.js and Convex stack
- Teams that need ready-made authentication flows instead of building from scratch
- Developers who want to reference how Better Auth and Convex are integrated
Getting started & customization
Use these recorded setup notes alongside the repository instructions for your chosen version.
- 1
Requires Node.js 18 or later; pnpm and the Convex CLI are recommended
- 2
Set SITE_URL, BETTER_AUTH_SECRET, and OAuth credentials separately in .env.local and the Convex environment
- 3
Email functionality requires configuring a Resend API key or SMTP credentials
- 4
OAuth callback URLs must be configured separately for development and production environments
- 5
When deploying to Vercel, use npx convex deploy --cmd 'pnpm run build' as the build command
License & source material
Usage conditions & limitations
Free to use · keep license noticeThis entry covers the free version of a public repository under the MIT license; the free scope applies to this version of the code and does not mean external services or third-party assets are free.
Must comply with when using
- You may use, modify, commercialize, and distribute this version of the code for free.
- When distributing copies or substantial portions of the code, retain the original author's copyright notice and the full MIT license notice.
- The code is provided as is; warranties and liability limitations are governed by the original license and applicable law.
Additional costs & items to verify
- Using this template requires registering and configuring external services yourself (Convex deployment, email service Resend or SMTP, and optional Google/GitHub/Slack OAuth); these services may incur costs or require accounts and API keys.
- Email functionality depends on the third-party service Resend, which requires registering an account and obtaining an API key; its free quota and pricing policy are determined by that provider.
- You must generate and configure BETTER_AUTH_SECRET yourself; otherwise the authentication flows will not work properly.
- The deployment example relies on the Vercel platform; actual deployment requires using that external hosting service and may incur costs.
- Demo images, fonts, icons, and other third-party assets must be checked against their respective licenses and cannot be judged solely by the code's MIT license.
- External services such as domains, hosting, databases, payments, or AI may charge additional fees.
View Original Text Basis
Permission is hereby granted, free of charge
Original License Text
You'll need to set up the following services:
Original README
Sign up at [Resend](https://resend.com/)
Original README
Generate a secure random string using: `openssl rand -base64 32`
Original README
https://github.com/podalls97/next-convex-betterauth-template/blob/main/LICENSEhttps://github.com/podalls97/next-convex-betterauth-template/blob/main/README.mdConnect your repository to [Vercel](https://vercel.com)
Original README
Compiled by DeepSeek based on repository license and README ·2026-10-03. Results only cover the materials read; dependencies, images, fonts, and subsequent term changes are subject to their respective original texts.
Project checks & description sources
Template Information
- Source platforms
- GitHub
- Documentation and maintenance reference score
- More documented · 87 / 100
- Technologies
- Next.js · React
- Website type
- Starter
How this score is calculated
Our heuristic uses license records (up to 30), a demo link (12), a preview (10), stars (15), recorded maintenance (15), description completeness (8), feature records (5) and classification data (5). It is not a code, security or performance test, or a Google score. A link does not establish tested functionality.
What to verify for this project
- Repository update recorded
- 2025-12-19
- Screenshot last checked
- 2026-10-03
A demo link is listed. Check it with your own content and viewport sizes; its presence does not confirm that forms, authentication or payments work.
The catalog identifies Next.js as the primary stack. Check the actual dependency manifest and lockfile for versions and hosting requirements. These notes use recorded metadata, not a code audit or a deployment test.
Use a selection guide →How this description was prepared
AI-assisted description based on catalog records and repository material. Repository authors are not automatically the reviewers of this description.
Review declaration: [email protected] · 2026-10-04
Inspect the recorded source material
SHA-256: fdc4b92998637700824f716f20c32ff4663b2c409897516b58f50b1f952d4b02
2026-10-03T16:57:16.635Z
Source file / repository# Next.js + Convex + Better Auth Template
[](https://nextjs.org/)
[](https://react.dev/)
[](https://convex.dev/)
[](https://better-auth.com/)
[](https://www.typescriptlang.org/)
[](https://opensource.org/licenses/MIT)

A **production-ready**, full-stack authentication template built with Next.js 16, Convex, and Better Auth. This template provides a complete authentication system with multiple auth methods, real-time database, comprehensive documentation, and API reference.
> **✨ New!** Built-in [Documentation](/documentation) and [API Reference](/api-reference) pages to help you get started quickly!
## 🚀 Features
### Authentication Methods
- ✅ **Email/Password** - Traditional authentication with secure password handling
- ✅ **OAuth Providers** - Google, GitHub, and Slack (via genericOAuth)
- ✅ **Magic Links** - Passwordless authentication via email
- ✅ **Email OTP** - One-time password verification
- ✅ **Two-Factor Authentication (2FA)** - TOTP-based 2FA with QR codes and backup codes
- ✅ **Anonymous Auth** - Guest access for users
### Core Features
- ✅ **Protected Routes** - Automatic route protection with Next.js 16 proxy pattern
- ✅ **Email Verification** - Verify user emails with secure tokens
- ✅ **Password Reset** - Secure password recovery flow
- ✅ **Modern UI** - Beautiful, responsive design with dark mode support
- ✅ **Type Safety** - Full TypeScript support with Convex
- ✅ **Real-time Database** - Powered by Convex for instant updates
- ✅ **Email Templates** - Pre-built React Email templates for all auth flows
### Developer Experience
- ✅ **Comprehensive Documentation** - Built-in `/documentation` page with setup guides
- ✅ **API Reference** - Full API documentation at `/api-reference` with code examples
- ✅ **Claude AI Ready** - Includes `CLAUDE.md` for AI coding assistants
- ✅ **TypeScript** - Full type safety throughout the stack
- ✅ **Tailwind CSS v4** - Modern styling with utility classes
- ✅ **Radix UI** - Accessible component primitives
## 📖 Quick Links
- 📚 **[Documentation](/documentation)** - Complete setup guide, architecture overview, and deployment instructions
- 🔧 **[API Reference](/api-reference)** - Comprehensive API documentation with copy-paste examples
- 🤖 **[CLAUDE.md](CLAUDE.md)** - Technical documentation for AI coding assistants
- 💬 **[GitHub Issues](https://github.com/podalls97/next-convex-betterauth-template/issues)** - Report bugs or request features
- ⭐ **[Star on GitHub](https://github.com/podalls97/next-convex-betterauth-template)** - Show your support!
## 📋 Prerequisites
Before you begin, ensure you have the following installed:
- [Node.js](https://nodejs.org/) (v18 or later)
- [pnpm](https://pnpm.io/) (recommended) or npm/yarn
- [Convex CLI](https://docs.convex.dev/get-started/quickstart)
## 🛠️ Setup Instructions
### 1. Clone the Repository
```bash
git clone https://github.com/podalls97/next-convex-betterauth-template.git
cd next-convex-betterauth-template
```
### 2. Install Dependencies
```bash
pnpm install
```
### 3. Set Up Environment Variables
Create a `.env.local` file in the root directory with the following variables:
```bash
# Convex (automatic)
CONVEX_DEPLOYMENT=automatic
NEXT_PUBLIC_CONVEX_URL=https://example.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL=https://example.convex.site
# Site Configuration
SITE_URL=http://localhost:3000
# Google OAuth (optional)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
# GitHub OAuth (optional)
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
# Better Auth
BETTER_AUTH_SECRET=
```
### 4. Set Up Convex Variables
After creating your `.env.local` file, set the required variables in Convex:
```bash
# Set up environment variables in Convex (development)
pnpm convex env set SITE_URL http://localhost:3000
pnpm convex env set BETTER_AUTH_SECRET your-secret-key-here
pnpm convex env set GOOGLE_CLIENT_ID your-google-client-id
pnpm convex env set GOOGLE_CLIENT_SECRET your-google-client-secret
pnpm convex env set GITHUB_CLIENT_ID your-github-client-id
pnpm convex env set GITHUB_CLIENT_SECRET your-github-client-secret
# Set up environment variables in Convex (production)
pnpm convex env set SITE_URL your-production-domain --prod
pnpm convex env set BETTER_AUTH_SECRET your-secret-key-here --prod
pnpm convex env set GOOGLE_CLIENT_ID your-google-client-id --prod
pnpm convex env set GOOGLE_CLIENT_SECRET your-google-client-secret --prod
pnpm convex env set GITHUB_CLIENT_ID your-github-client-id --prod
pnpm convex env set GITHUB_CLIENT_SECRET your-github-client-secret --prod
```
### 6. Required API Keys
You'll need to set up the following services:
#### 📧 Email Service (Choose one)
**Option 1: Resend (Recommended)**
- Sign up at [Resend](https://resend.com/)
- Get your API key from the dashboard
- Add `RESEND_API_KEY` to your environment variables in Convex
**Option 2: SMTP (Gmail/Outlook)**
- For Gmail: Enable 2FA and create an App Password
- For Outlook: Use your regular credentials
- Add SMTP variables to your environment
#### 🔐 Better Auth Secret
- Generate a secure random string using: `openssl rand -base64 32`
- Add to `BETTER_AUTH_SECRET` in both `.env.local` and Convex
#### 🔑 OAuth Providers (Optional)
**Google OAuth**
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or select an existing one
3. Navigate to "APIs & Services" > "Credentials"
4. Click "Create Credentials" > "OAuth 2.0 Client ID"
5. Configure consent screen if prompted
6. Set application type to "Web application"
7. Add authorized redirect URIs:
- Development: `http://localhost:3000/api/auth/callback/google`
- Production: `https://yourdomain.com/api/auth/callback/google`
8. Copy `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`
**GitHub OAuth**
1. Go to [GitHub Developer Settings](https://github.com/settings/developers)
2. Click "New OAuth App"
3. Fill in the details:
- Application name: Your app name
- Homepage URL: `http://localhost:3000` (dev) or your production URL
- Authorization callback URL:
- Development: `http://localhost:3000/api/auth/callback/github`
- Production: `https://yourdomain.com/api/auth/callback/github`
4. Copy `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`
**Slack OAuth (via genericOAuth)**
1. Go to [Slack API](https://api.slack.com/apps)
2. Click "Create New App" > "From scratch"
3. Configure OAuth & Permissions
4. Add redirect URL: `http://localhost:3000/api/auth/callback/slack`
5. Copy `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET`
6. Update `convex/auth.ts` and `src/lib/auth-client.ts` to include Slack configuration
### 5. Start Development
#### Option 1: Start Everything (Recommended)
```bash
# This will automatically start both Convex dev and Next.js dev
pnpm dev
```
#### Option 2: Start Convex Only
```bash
# Start Convex development server only
pnpm convex dev
# Or run once and exit
pnpm convex dev --once
```
**Note**: If you encounter errors after running `pnpm install` after cloning this repo, make sure you have added the required environment variables to your `.env.local` file, then run `pnpm convex env set` to set up the variables in Convex.
The `pnpm dev` command will:
- Start Convex development server
- Start Next.js development server
- Open your browser to `http://localhost:3000`
## 🎯 Quick Start Guide
1. **Sign Up**: Create a new account at `/sign-up`
2. **Verify Email**: Check your email and click the verification link
3. **Sign In**: Use your credentials at `/sign-in`
4. **Dashboard**: Access your protected dashboard at `/dashboard`
5. **Settings**: Configure 2FA and other settings at `/settings`
## 📁 Project Structure
```
src/
├── app/
│ ├── (auth)/ # Protected routes (requires authentication)
│ │ ├── dashboard/ # Main user dashboard
│ │ ├── settings/ # User settings (2FA, profile)
│ │ ├── documentation/ # 📚 Built-in documentation page
│ │ └── api-reference/ # 🔧 Built-in API reference
│ ├── (unauth)/ # Public routes
│ │ ├── sign-in/ # Sign in page
│ │ ├── sign-up/ # Registration page
│ │ ├── verify-2fa/ # 2FA verification
│ │ └── reset-password/ # Password reset
│ └── api/auth/[...all]/ # Next.js API route (delegates to Convex)
├── components/
│ ├── client/ # Client components
│ └── server/ # Server components
├── lib/
│ ├── auth.ts # Better Auth server configuration
│ └── auth-client.ts # Better Auth client hooks
└── proxy.ts # Route protection (Next.js 16 proxy pattern)
convex/
├── auth.config.ts # Better Auth domain configuration
├── auth.ts # Better Auth + Convex integration
├── schema.ts # Convex database schema
├── http.ts # HTTP routes for Better Auth
├── users.ts # Internal mutations for user syncing
├── email.tsx # Email templates (React Email)
└── polyfills.ts # Required for Better Auth in Convex
```
## 🔧 Adding New Pages
To add new pages to your dashboard:
1. Create a new directory in `src/app/(auth)/dashboard/`
2. Add a `page.tsx` file
3. Use the provided components:
```tsx
"use client";
import { useQuery } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { AppContainer } from "@/components/server";
export default function MyPage() {
const user = useQuery(api.auth.getCurrentUser);
return (
<AppContainer>
<h1>Hello {user?.name}!</h1>
{/* Your page content */}
</AppContainer>
);
}
```
## 🚀 Deployment
### Deploy to Vercel
1. Push your code to GitHub
2. Connect your repository to [Vercel](https://vercel.com)
3. Configure build settings:
- **Build Command**: `npx convex deploy --cmd 'pnpm run build'`
- **Install Command**: `pnpm install`
4. Add environment variables in Vercel dashboard:
- All variables from your `.env.local` file
- **Additional variables for production**:
- `CONVEX_SITE_URL=your-domain` (your production domain)
- `CONVEX_DEPLOYMENT=key from convex dashboard` (available in Convex dashboard under Settings > Deployment URL and Deploy Key)
5. Deploy!
### Deploy Convex
```bash
pnpm convex deploy
```
## 📚 Learn More
- [Next.js Documentation](https://nextjs.org/docs)
- [Convex Documentation](https://docs.convex.dev)
- [Better Auth Documentation](https://www.better-auth.com/docs)
- [Resend Documentation](https://resend.com/docs)
## 🤖 For AI Agents & Developers
If you're working with AI coding assistants or need to modify authentication providers:
### Adding/Removing Auth Providers
When adding or removing authentication providers (Google, GitHub, etc.):
1. **Update Environment Variables**: Add or remove the corresponding `CLIENT_ID` and `CLIENT_SECRET` variables in both `.env.local` and Convex
2. **Check Convex Configuration**: Review and update `convex/auth.config.ts` to include/exclude the provider
3. **Update Mutations**: Ensure all related Convex mutations and functions are updated to handle the new/removed provider
4. **Test Authentication Flow**: Verify the complete authentication flow works with the changes
### Quick Provider Management
- **To add a provider**: Configure the provider in `convex/auth.config.ts`, add environment variables, and update any related mutations
- **To remove a provider**: Remove from auth config, clean up environment variables, and update mutations to handle the removal
## 🤝 Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 🆘 Support
If you encounter any issues:
1. Check the [Issues](https://github.com/podalls97/next-convex-betterauth-template/issues) page
2. Create a new issue with detailed information
3. Join our community discussions
---
**Happy coding! :DD**
Explore similar templates
Compare previews and descriptions within the same stack and category.

Next.js SaaS Starter
The official Next.js SaaS starter template, integrating email/password authentication, Stripe Checkout subscriptions, a dashboard with user/team CRUD, basic Owner/Member RBAC, and activity logging.
Next.js · SaaS

Next.js Commerce
Vercel's officially maintained Next.js App Router ecommerce starter with deep Shopify integration, offering a complete product catalog, cart, and checkout flow. Core logic is modular for swapping backends, and community provider versions exist for BigCommerce, Medusa, and Saleor.
Next.js · E-commerce

Next-js-Boilerplate
A developer-first Next.js 16 starter with Tailwind CSS 4 and TypeScript, supporting both App Router and Page Router.
Next.js · Starter

tailwind-nextjs-starter-blog
A Next.js and Tailwind CSS blog starter template using Contentlayer for Markdown/MDX, with built-in SEO, code highlighting, and tags. It targets personal technical blogs and migration from Jekyll/Hugo to React, and supports one-click Vercel deployment.
Next.js · Blog

next-forge
next-forge is a Turborepo-based Next.js template maintained by Vercel, positioned as a starting point for SaaS products.
Next.js · Starter

SaaS-Boilerplate
SaaS-Boilerplate is an open-source SaaS starter template built with Next.js App Router, React 19, TypeScript, Tailwind CSS, and Shadcn UI.
Next.js · SaaS
