Quick Setup
Set up Supabase (Dashboard)
- Copy your Project URL and anon public key (Dashboard → Settings → API). You can start from the Supabase Dashboard.
- Set your Site URL and add
/auth/callbackto Additional Redirect URLs for dev and prod (Dashboard → Auth → URL Configuration). Guide: Redirect URLs. - Optional: enable your social providers (e.g., Google, GitHub, Apple, Facebook) and use
/auth/callbackas the callback (Dashboard → Auth → Providers). See the full list: Social login. Example guide: Login with Google.
/auth/callback is whitelisted for the domains you use, and (if enabled) providers redirect back successfully.Define environment variables
.env (or .env.local) and to your hosting provider.Verify preconfigured clients
- Browser client:
src/lib/supabase/client.ts - Server client (cookies wired):
src/lib/supabase/server.ts
NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY.Route protection (summary)
- keeps auth cookies in sync for SSR,
- redirects signed-out users away from protected pages,
- redirects signed-in users away from auth pages.
Authentication Flows
Sabo supports four main authentication flows:- Email/Password - Traditional email and password sign-in/sign-up
- Magic Link - Passwordless authentication via email link
- OAuth - Social login with Google, GitHub, Apple
- Password Reset - Forgot password and reset flow
Email/Password Flow
Sign In Flow
The email/password sign-in uses a two-step UX for better security and flexibility:Step 1: Enter email (/sign-in)
/sign-in page.- Email is validated (client-side)
- Email is stored in
sessionStoragefor next step - User is redirected to
/sign-in/confirm
Step 2: Choose authentication method (/sign-in/confirm)
- Magic Link - Send a passwordless login link via email
- Password - Enter password to sign in
- Email is retrieved from
sessionStorageand shown (disabled) - User can choose Magic Link OR password
- Password sign-in → calls
signIn()server action → redirects to/dashboard - Magic Link → calls
signInWithMagicLink()→ sends email → user waits for email
Server action: signIn()
- Supabase verifies email/password
- If successful: sets session cookie and redirects to
/dashboard - If failed: returns error message
Sign Up Flow
Sign-up follows a similar two-step pattern:Step 1: Enter name and email (/sign-up)
Step 2: Choose registration method (/sign-up/confirm)
- Magic Link - Complete registration via email link (no password needed)
- Password - Create a password-based account
Server action: signUp()
- Supabase creates new user account
- Sends confirmation email with link to
/auth/callback - User must click email link to activate account
- After activation: redirected to
/dashboard
Magic Link Flow
Magic Links provide passwordless authentication - users receive an email with a one-time login link.User requests magic link
/sign-in/confirm or /sign-up/confirm, user clicks “Send magic link” button.Server action sends email
- Supabase sends email with magic link
- Email contains link like:
https://yourapp.com/auth/callback?token_hash=abc123&type=email - User clicks link in email
Callback handles magic link
/auth/callback?token_hash=...&type=email- Supabase verifies the OTP token
- If valid: creates session and redirects to
/dashboard - If invalid/expired: redirects to
/sign-in?error=auth_failed
OAuth Flow
Sabo supports OAuth social login with Google, GitHub, and Apple.Configure OAuth providers (Supabase)
- Go to Supabase Dashboard → Authentication → Providers
- Enable your desired providers (Google, GitHub, Apple)
- For each provider, set:
- Client ID (from provider’s developer console)
- Client Secret (from provider’s developer console)
- Redirect URL: Use Supabase’s callback URL (automatically provided)
User clicks OAuth button
/sign-in or /sign-up pages:Server action initiates OAuth
- Supabase generates OAuth URL for the provider
- User is redirected to provider’s login page (e.g., Google sign-in)
- User grants permission to your app
Provider redirects to callback
- Callback exchanges OAuth code for session
- Creates user account if first-time sign-in
- Redirects to
/dashboard(or customnextURL)
Password Reset Flow
Users who forget their password can reset it via email.User requests password reset (/forgot-password)
Server action sends reset email
- Supabase sends password reset email
- Email contains link like:
https://yourapp.com/auth/callback?token_hash=xyz&type=recovery - User clicks link
Callback redirects to reset page
/auth/callback?token_hash=...&type=recovery- Callback verifies reset token
- If valid: redirects to
/reset-password - User is now authenticated with a temporary session
User enters new password (/reset-password)
Server action updates password
- Supabase updates user’s password
- Session is maintained (user is still authenticated)
- Redirects to
/sign-inwith success message - User can now sign in with new password
Auth Callback Route
The/auth/callback route is the central hub for all authentication flows. It handles:
- OAuth code exchange
- Magic link verification
- Email confirmation
- Password reset links
Error Handling & UI Patterns
Loading States
All auth actions should show loading indicators:Error States
Display errors from server actions:Toast Notifications
Usesonner for success messages: