Supabase Auth
Last updated December 18, 2025
Overview
Supabase Auth provides a complete authentication solution with email/password, magic links, OAuth providers, and user management. It's integrated with Supabase's database and real-time features.
Create Supabase Project
- Go to supabase.com and sign up
- Click "New Project"
- Fill in project details (name, database password, region)
- Click "Create new project"
- Wait for provisioning (2-3 minutes)
Get API Credentials
- In your Supabase project dashboard, go to "Settings" → "API"
- You'll find these values:
- Project URL:
https://xxx.supabase.co(this is yourNEXT_PUBLIC_SUPABASE_URL) - anon public key: A long string starting with
eyJ...(this is yourNEXT_PUBLIC_SUPABASE_ANON_KEY) - service_role key: Another long string (this is your
SUPABASE_SERVICE_ROLE_KEY- keep this secret!)
- Project URL:
- Copy these values - you'll need them in the next step
Configure Auth Settings
- Go to "Authentication" → "Providers" in your Supabase dashboard
- Enable the providers you want (Email, Google, GitHub, etc.)
- For Email provider:
- Enable "Enable email confirmations" if you want email verification
- Configure email templates in "Email Templates"
- For OAuth providers (e.g., Google):
- Enable the provider
- Add your OAuth client ID and secret (from Google Cloud Console)
- Add redirect URL:
https://yourproject.supabase.co/auth/v1/callback
- Go to "Authentication" → "URL Configuration"
- Add your site URL:
http://localhost:3000(for development) - Add redirect URLs:
http://localhost:3000/auth/callbackhttps://yourdomain.com/auth/callback(for production)
Environment Variables
Add these variables to your .env.local file:
# Supabase NEXT_PUBLIC_SUPABASE_URL="https://xxx.supabase.co" NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." SUPABASE_SERVICE_ROLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." # Server-side only
Important:
NEXT_PUBLIC_SUPABASE_URLis your project URL from "Settings" → "API"NEXT_PUBLIC_SUPABASE_ANON_KEYis the anon/public key (safe to expose in client)SUPABASE_SERVICE_ROLE_KEYis the service role key (NEVER expose in client - server-side only)- All
NEXT_PUBLIC_*variables are exposed to the browser
Testing
- Restart your dev server:
npm run dev - Navigate to
http://localhost:3000/sign-up - Try creating an account with email/password
- Check your email for the verification link (if enabled)
- Try signing in with OAuth provider (if configured)
- Verify user appears in Supabase dashboard → "Authentication" → "Users"
Troubleshooting:
- If sign-up fails, check that email provider is enabled in Supabase dashboard
- For OAuth, verify redirect URLs match exactly in both Supabase and OAuth provider
- Check browser console and Supabase logs for error details
- Ensure environment variables are correctly set