Skip to content

omransoliman97/nextjs-supabase-auth-osdev

Repository files navigation

Supabase Auth Template

A complete Next.js authentication template with Supabase including all auth providers.

A production-ready Next.js authentication template powered by Supabase, including all authentication providers (email, OAuth, password reset, email confirmation) with a modern UI.

Video Tutorial

Link: Coming Soon

πŸ“Έ Gallery

View Gallery

Click image or here to view full gallery β†’

πŸš€ Quick Start

Using npx (Recommended)

npx osdev-auth-supabase my-app
cd my-app
npm run dev

Manual Setup

If you cloned the repository directly:

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your Supabase credentials

# Run development server
npm run dev

See INSTRUCTIONS.md for detailed setup steps.

✨ What's Included

  • βœ… Complete Authentication Flows

    • Sign up with email/password
    • Login with email/password
    • Password reset flow
    • Email confirmation
    • OAuth callback handling
  • βœ… All Supabase Auth Providers Supported

    • Google, GitHub, and more
    • Easy to add additional providers
  • βœ… User Data Storage

    • User data stored in raw_user_meta_data:
      {
        first_name: "Omran",
        last_name: "Soliman"
      }
  • βœ… Modern UI

    • Built with shadcn/ui components
    • Dark/Light theme support
    • Toast notifications
    • Responsive design
  • βœ… Error Handling

    • Custom error pages
    • 404 not found page
    • Proper error messages
  • βœ… TypeScript

    • Fully typed for better DX
    • Type-safe Supabase client

πŸ“¦ Dependencies

All required dependencies are included in package.json:

  • Supabase: @supabase/supabase-js, @supabase/ssr
  • UI Components: shadcn/ui (alert, button, card, input, label, sonner)
  • Icons: react-icons, lucide-react
  • Theme: next-themes

πŸ“ Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ (auth)/
β”‚   β”‚   β”œβ”€β”€ login/              # Login page
β”‚   β”‚   β”œβ”€β”€ signup/             # Signup page
β”‚   β”‚   β”œβ”€β”€ forgot-password/    # Password reset request
β”‚   β”‚   β”œβ”€β”€ reset-password/     # Update password page
β”‚   β”‚   └── auth/
β”‚   β”‚       β”œβ”€β”€ callback/       # OAuth callback handler
β”‚   β”‚       β”œβ”€β”€ confirm/        # Email confirmation handler
β”‚   β”‚       └── confirmed/      # Confirmation success page
β”‚   β”œβ”€β”€ error/                  # Custom error page
β”‚   β”œβ”€β”€ not-found/              # 404 page
β”‚   └── home/                   # Protected home page (example)
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ LoginForm.tsx
β”‚   β”œβ”€β”€ SignupForm.tsx
β”‚   β”œβ”€β”€ RequestResetForm.tsx
β”‚   β”œβ”€β”€ UpdatePasswordForm.tsx
β”‚   β”œβ”€β”€ ProvidersButtons.tsx
β”‚   └── ThemeToggle.tsx
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ auth-functions.ts       # All auth operations
β”‚   β”œβ”€β”€ auth-utils.ts           # Server-side utilities
β”‚   └── auth-utils-client.ts    # Client-side utilities
β”œβ”€β”€ hooks/
β”‚   └── useAuthRedirectClient.ts
β”œβ”€β”€ utils/supabase/
β”‚   β”œβ”€β”€ client.ts
β”‚   β”œβ”€β”€ server.ts
β”‚   └── middleware.ts
β”œβ”€β”€ IMPORTANT/
β”‚   β”œβ”€β”€ EmailConfirmSignUp.md   # Email template
β”‚   └── EmailResetPassword.md   # Email template
β”œβ”€β”€ middleware.ts               # Auth middleware
└── INSTRUCTIONS.md             # Complete setup guide

πŸ”§ Setup Requirements

Prerequisites

  • Node.js 18.0 or higher
  • npm or yarn
  • Supabase account (Sign up here)

Environment Variables

Create a .env.local file:

NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

Get these from your Supabase Dashboard β†’ Settings β†’ API

Supabase Configuration

  1. Email Templates (Authentication β†’ Email Templates):

    • Update "Confirm Signup" template (see IMPORTANT/EmailConfirmSignUp.md)
    • Update "Reset Password" template (see IMPORTANT/EmailResetPassword.md)
  2. URL Configuration (Authentication β†’ URL Configuration):

    • Site URL: http://localhost:3000
    • Redirect URLs:
      • http://localhost:3000/auth/callback
      • http://localhost:3000/auth/confirm
  3. OAuth Providers (Optional):

    • Enable providers in Authentication β†’ Providers
    • Add OAuth credentials

πŸ› οΈ Commands

# Development
npm run dev          # Start dev server at http://localhost:3000

# Production
npm run build        # Build for production
npm start           # Start production server

# Code Quality
npm run lint        # Run ESLint

🌐 Deploy

Vercel (Recommended)

  1. Push code to GitHub
  2. Import to Vercel
  3. Add environment variables
  4. Deploy

Don't forget to update Supabase URLs with your production domain!

πŸ“š Documentation

  • INSTRUCTIONS.md - Complete setup guide with troubleshooting
  • IMPORTANT/ - Email templates for Supabase
  • Code Comments - Every file is well-documented

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT Β© Omran Soliman

πŸ”— Links

⭐ Support

If this template helped you, please:

🎯 Perfect For

  • SaaS applications
  • Social platforms
  • Community websites
  • E-commerce sites
  • Any project requiring authentication

Made with ❀️ by Omran Soliman

Releases

No releases published

Packages

 
 
 

Contributors