Prerequisites
Before you begin, ensure you have the following installed:VS Code
Microsoft’s code editor
Dev Containers Extension
Run dev environments in containers
Docker
Container runtime
The Dev Container setup is the recommended way to get started. It automatically provisions Node.js (via Volta), Python (via pyenv), and PostgreSQL 18 in an isolated Ubuntu container.
Installation Steps
Clone the Repository
Clone the Auth UI Boilerplate repository to your local machine:Open the project in VS Code:
Open in Dev Container
Once VS Code opens, you’ll see a notification to “Reopen in Container”.Alternatively, manually trigger it:The Dev Container configuration (
- Press
Cmd+Shift+P(Mac) orCtrl+Shift+P(Windows/Linux) - Type “Dev Containers: Reopen in Container”
- Select the command
The first build takes 2-5 minutes as Docker downloads the base image and sets up PostgreSQL 18, Node.js, Python, and Zsh with plugins.
.devcontainer/devcontainer.json) provides:- Ubuntu base with common utilities
- Volta for Node.js version management
- pyenv for Python version management
- PostgreSQL 18 running on
postgres:5432 - Zsh with autosuggestions and syntax highlighting
Install Runtime Prerequisites
Once inside the container, install Node.js and Python:This installs the Node.js version specified in Verify installations:
package.json (Node.js 22+).If you plan to use the Python backend examples, also install Python:Configure Environment Variables
Copy the example environment file:The Replace
.env file contains the following configuration:.env
Generate Better Auth Secret
Generate a secure random secret for signing tokens:BETTER_AUTH_SECRET in .env with the generated value.Set Up Google OAuth
To enable Google sign-in, you need OAuth credentials from Google Cloud:
- Go to Google Cloud Console
- Create a new project (or select an existing one)
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth 2.0 Client ID
- Configure the OAuth consent screen if prompted
- Select Application type: Web application
- Add Authorized redirect URI:
- Click Create and copy the Client ID and Client Secret
- Paste them into your
.envfile:
.env
If you don’t want to use Google OAuth during development, you can skip this step and use email/password authentication instead. However, the Google sign-in button will not work.
Install Dependencies
Install all npm packages:This installs:
- Next.js 16 (React 19)
- Better Auth (authentication library)
- Drizzle ORM (database toolkit)
- shadcn/ui components (Tailwind CSS)
- Axios (HTTP client)
- Motion (animations)
Push Database Schema
Create the required database tables in PostgreSQL:This command runs
drizzle-kit push, which:- Reads the schema from
src/db/schema.ts - Creates tables:
user,session,account,verification,jwks - Does not generate migration files (for quick dev iteration)
db:push is recommended for development. For production, use npm run db:generate to create migration files, then npm run db:migrate to apply them.Database Schema
The following tables are created automatically by Better Auth:| Table | Description |
|---|---|
user | User accounts (id, name, email, image, timestamps) |
session | Active sessions with tokens and expiration |
account | OAuth provider accounts (Google, GitHub, etc.) |
verification | Email verification tokens |
jwks | JSON Web Key Set for JWT signing/verification |
Start the Development Server
Run the Next.js dev server:The application will start on http://localhost:3000.You should see output similar to:
Test Authentication
Open your browser and navigate to http://localhost:3000.
Sign Up with Email
- Click Sign Up in the navigation
- Enter your email and password
- Click Create Account
- You’ll be redirected to the home page, now authenticated
Sign In with Google
- Click Sign In in the navigation
- Click Sign in with Google
- Complete the Google OAuth flow
- You’ll be redirected back to the application
Verify Session
After signing in, you should see:- Your name and email displayed in the “Authentication Status” card
- A Sign Out button
- Access to protected features
The home page includes an API Test section for testing backend integration. This requires setting
BACKEND_API_URL and running a backend service. See the Backend Integration guide for details.What’s Next?
Environment Variables
Learn about all available configuration options
Database Management
Add custom tables and run migrations with Drizzle
Backend Integration
Connect Go, Python, or Express.js backends
Customize UI
Remove demo components and build your app
Troubleshooting
Dev Container fails to build
Dev Container fails to build
Solution: Ensure Docker is running and you have the Dev Containers extension installed. Check Docker Desktop for error logs.
Database connection fails
Database connection fails
Solution: The Dev Container PostgreSQL service may not have started. Check the logs:Restart the container if needed.
Google OAuth returns 'redirect_uri_mismatch'
Google OAuth returns 'redirect_uri_mismatch'
Solution: Ensure your redirect URI in Google Cloud Console exactly matches:No trailing slashes, correct port, and
http (not https) for local dev.npm run dev shows 'BETTER_AUTH_SECRET is not set'
npm run dev shows 'BETTER_AUTH_SECRET is not set'
Solution: Make sure you copied Paste the result into
.env.example to .env and generated a secret:BETTER_AUTH_SECRET in your .env file.