A modern, secure, and production-ready authentication template built with Next.js 14 and Supabase. This template provides a complete authentication system with multiple OAuth providers, reCAPTCHA protection, and a beautiful responsive UI.
- Email/Password Authentication - Secure user registration and login
- Multiple OAuth Providers - Google, Apple, and more
- reCAPTCHA Protection - Bot prevention and spam protection
- Email Verification - Secure email confirmation system
- Password Reset - Secure password recovery flow
- JWT Token Management - Automatic session handling
- Protected Routes - Route-level authentication guards
- Modern Design - Clean, professional interface
- Responsive Layout - Perfect on desktop, tablet, and mobile
- Smooth Animations - Engaging user interactions
- Dark/Light Mode - Theme switching support
- Form Validation - Real-time input validation
- Loading States - Beautiful loading indicators
- Next.js 14 - Latest features and optimizations
- Server Components - Enhanced performance
- Optimized Images - Automatic image optimization
- Code Splitting - Efficient bundle loading
- SEO Optimized - Meta tags and structured data
- Node.js 18.0 or later
- npm, yarn, pnpm, or bun
- Supabase Account - Create one here
- Google OAuth Credentials (optional)
- Apple Developer Account (optional)
- reCAPTCHA Site Key (optional)
- Clone the repository
git clone https://github.com/wardaowais/Supabase-Next-Auth-Template.git
cd supabase-auth-template- Install dependencies
npm install
# or
yarn install
# or
pnpm install
# or
bun install- Set up environment variables
Create a .env.local file in the root directory:
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_SUPABASE_PROJECT_ID=your_project_id
# Database Password (for reference)
NEXT_PUBLIC_SUPABASE_PASSWORD=your_database_password
# reCAPTCHA (optional but recommended)
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=your_recaptcha_site_key
# OAuth Providers (optional)
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your_google_client_id
NEXT_PUBLIC_APPLE_CLIENT_ID=your_apple_client_id- Configure Supabase
In your Supabase dashboard:
- Go to Authentication β Settings
- Add your site URL:
http://localhost:3000 - Configure OAuth providers (Google, Apple, etc.)
- Enable email confirmations if desired
- Set up reCAPTCHA (optional)
- Go to Google reCAPTCHA
- Create a new site key
- Add your domain:
localhostfor development - Copy the site key to your
.env.local
- Run the development server
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 in your browser to see the result.
βββ app/
β βββ (auth)/
β β βββ sign-in/
β β βββ sign-up/
β β βββ reset-password/
β βββ dashboard/
β βββ globals.css
β βββ layout.js
β βββ page.js
βββ components/
β βββ ui/
β βββ auth/
β βββ Navbar.js
β βββ Footer.js
βββ lib/
β βββ supabase/
β β βββ client.js
β β βββ server.js
β βββ utils.js
βββ public/
βββ README.md
- Create a new Supabase project
- Go to Settings β API
- Copy your URL and anon key
- Add to your
.env.localfile
- Go to Google Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
https://your-project.supabase.co/auth/v1/callback
- Add client ID to Supabase Auth settings
- Go to Apple Developer
- Create a new identifier
- Configure Sign in with Apple
- Add client ID to Supabase Auth settings
- Visit reCAPTCHA Admin
- Create a new site
- Choose reCAPTCHA v2 or v3
- Add your domains
- Copy site key to environment variables
import { createClient } from '@/lib/supabase/client'
const supabase = createClient()
// Sign up
const { data, error } = await supabase.auth.signUp({
email: 'user@example.com',
password: 'password123'
})
// Sign in
const { data, error } = await supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'password123'
})
// Sign out
const { error } = await supabase.auth.signOut()// Google OAuth
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: `${origin}/auth/callback`
}
})
// Apple OAuth
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'apple',
options: {
redirectTo: `${origin}/auth/callback`
}
})import { createClient } from '@/lib/supabase/server'
import { redirect } from 'next/navigation'
export default async function ProtectedPage() {
const supabase = createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) {
redirect('/sign-in')
}
return <div>Protected content</div>
}The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
- Push your code to GitHub
- Import your repository to Vercel
- Add environment variables in Vercel dashboard
- Update Supabase settings with your production URL
- Deploy!
- Netlify - Static site hosting
- Railway - Full-stack deployment
- Digital Ocean - VPS deployment
- AWS Amplify - Serverless deployment
| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Your Supabase project URL | β |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Your Supabase anon key | β |
NEXT_PUBLIC_SUPABASE_PROJECT_ID |
Your Supabase project ID | β |
NEXT_PUBLIC_RECAPTCHA_SITE_KEY |
Google reCAPTCHA site key | |
NEXT_PUBLIC_GOOGLE_CLIENT_ID |
Google OAuth client ID | β Optional |
NEXT_PUBLIC_APPLE_CLIENT_ID |
Apple OAuth client ID | β Optional |
Need to update recaptcha just
- Tailwind CSS - Utility-first CSS framework
- Custom Components - Reusable UI components
- Theme Configuration - Easy color and font customization
- Configure provider in Supabase dashboard
- Add client credentials to environment variables
- Update OAuth component with new provider
- Modify components in
/components/auth/ - Update authentication logic in
/lib/supabase/ - Add custom validation rules
- Next.js Documentation - Learn about Next.js features and API
- Learn Next.js - Interactive Next.js tutorial
- Next.js GitHub repository
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
If you have any questions or need help, please:
- Open an issue on GitHub
- Check the documentation
- Join the Supabase Discord
If this project helped you, please give it a β on GitHub!
Built with β€οΈ using Next.js and Supabase