A modern, production-ready authentication template built with Next.js 14+, TypeScript, Supabase, and Tailwind CSS. Features email/password authentication and GitHub OAuth with a sleek, dark-themed UI.
- 🎨 Modern Dark UI - Sleek black theme with glass-morphism design
- 📧 Email/Password Authentication - Secure email-based signup and login
- 🔗 GitHub OAuth - One-click social authentication
- 🔒 Protected Routes - Automatic route protection with middleware
- ✅ Email Verification - Built-in email confirmation flow
- 🍪 Cookie-based Sessions - Secure session management
- 📱 Fully Responsive - Works seamlessly on all devices
- ⚡ Server & Client Components - Optimized for Next.js App Router
- 🎯 TypeScript - Full type safety throughout
- Node.js 18+ installed
- A Supabase account (signup here)
- Git installed
git clone https://github.com/arththakkar1/next-supabase-authentication.git
cd supabase-nextjs-auth-templatenpm installCreate a .env.local file in the root directory:
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-keyTo get your Supabase credentials:
- Go to your Supabase Dashboard
- Select your project
- Go to Settings → API
- Copy the Project URL and anon/public key
- Go to Authentication → Providers in Supabase Dashboard
- Enable the Email provider
- Configure email templates (optional)
-
Create a GitHub OAuth App:
- Go to GitHub Settings → Developer settings → OAuth Apps → New OAuth App
- Application name: Your app name
- Homepage URL:
http://localhost:3000(for development) - Authorization callback URL:
https://your-project-ref.supabase.co/auth/v1/callback - Click Register application
- Copy the Client ID
- Generate and copy the Client Secret
-
Configure in Supabase:
- Go to Authentication → Providers
- Enable GitHub provider
- Paste your Client ID and Client Secret
- Click Save
- Go to Authentication → URL Configuration
- Set Site URL:
http://localhost:3000(for development) - Add Redirect URLs:
http://localhost:3000/auth/callbackhttp://localhost:3000/auth/confirm
- Go to Authentication → Email Templates
- Edit the Confirm signup template
- Update the confirmation URL to:
{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email
npm run devOpen http://localhost:3000 in your browser.
├── app/
│ ├── auth/
│ │ ├── callback/
│ │ │ └── route.ts # OAuth callback handler
│ │ ├── confirm/
│ │ │ └── route.ts # Email confirmation handler
│ │ ├── error/
│ │ │ └── page.tsx # Error page
│ │ └── signout/
│ │ └── route.ts # Sign out handler
│ ├── dashboard/
│ │ └── page.tsx # Protected dashboard
│ ├── login/
│ │ └── page.tsx # Login page
│ ├── signup/
│ │ └── page.tsx # Signup page
│ └── page.tsx # Home page
├── components/
│ └── auth/
│ ├── SignInForm.tsx # Sign in component
│ └── SignUpForm.tsx # Sign up component
├── lib/
│ └── supabase/
│ ├── client.ts # Client-side Supabase client
│ ├── server.ts # Server-side Supabase client
│ └── middleware.ts # Auth middleware helper
├── middleware.ts # Next.js middleware
├── .env.local # Environment variables
└── README.md
Create a .env.local file with the following variables:
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-hereThe middleware automatically handles session refresh. To protect specific routes, update middleware.ts:
export const config = {
matcher: [
"/dashboard/:path*", // Protect dashboard routes
"/profile/:path*", // Protect profile routes
// Add more protected routes here
],
};The template uses Tailwind CSS with a dark theme. Main colors:
- Background:
bg-black - Cards:
bg-zinc-900 - Borders:
border-zinc-800 - Primary:
bg-blue-600 - Text:
text-white,text-zinc-400
Customize colors in tailwind.config.ts:
theme: {
extend: {
colors: {
primary: '#3b82f6', // Change primary color
// Add custom colors
},
},
}To add more OAuth providers (Google, Discord, etc.):
- Enable the provider in Supabase Dashboard
- Update the auth components to include new provider buttons
- Use the same
signInWithOAuthpattern:
await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${window.location.origin}/auth/callback`,
},
});| Route | Description | Protected |
|---|---|---|
/ |
Home page | No |
/login |
Sign in page | No |
/signup |
Sign up page | No |
/dashboard |
User dashboard | Yes |
/profile |
User profile | Yes |
/auth/callback |
OAuth callback | No |
/auth/confirm |
Email confirmation | No |
/auth/error |
Auth error page | No |
- ✅ Server-side session validation
- ✅ Automatic token refresh
- ✅ Secure cookie management
- ✅ Protected API routes
- ✅ CSRF protection via Supabase
- ✅ Email verification
- ✅ Rate limiting (Supabase built-in)
- Push your code to GitHub
- Import project to Vercel
- Add environment variables in Vercel dashboard
- Update Supabase URL configuration with your production URL
- Deploy!
- Go to Authentication → URL Configuration
- Update Site URL to your production domain
- Add production Redirect URLs:
https://yourdomain.com/auth/callbackhttps://yourdomain.com/auth/confirm
- Update GitHub OAuth callback URL to production domain
- Check that the confirmation URL in email templates is correct
- Verify redirect URLs are configured in Supabase
- Check browser console for errors
- Verify GitHub OAuth callback URL matches Supabase
- Check that Client ID and Secret are correct
- Ensure GitHub OAuth app is not suspended
- Clear browser cookies and try again
- Check that middleware is properly configured
- Verify environment variables are set correctly
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
If you have any questions or run into issues, please:
- Check the Troubleshooting section
- Open an issue on GitHub
- Consult the Supabase Discord
Create a .env.local file in your project root:
# ============================================
# SUPABASE CONFIGURATION
# ============================================
# Get these values from your Supabase Dashboard:
# https://supabase.com/dashboard/project/YOUR-PROJECT/settings/api
# Your Supabase project URL
NEXT_PUBLIC_SUPABASE_URL=https://xxxxxxxxxxxxx.supabase.co
# Your Supabase anonymous/public key
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.xxxxxxxxxxxxx
# ============================================
# OPTIONAL: FOR PRODUCTION
# ============================================
# Only needed if you want different values for production
# NEXT_PUBLIC_SITE_URL=https://yourdomain.comMade with ❤️ using Next.js and Supabase