Overview
The Dodo Starter kit implements secure authentication using Google OAuth via Supabase Auth. The authentication flow is streamlined and production-ready, handling user sign-in, session management, and automatic user creation.Authentication Flow
1. Google Sign-In Component
The main authentication entry point is theGoogleSignIn component, which initiates the OAuth flow:
components/auth/google-signin.tsx
- Client-side Supabase client initialization
- Loading state management during OAuth redirect
- Custom redirect URL to handle the callback
- Branded Google button with icon
2. Login Page
The login page checks for existing authentication and redirects authenticated users:app/login/page.tsx
3. OAuth Callback Handler
After Google authenticates the user, Supabase redirects to the callback route:app/api/auth/callback/route.ts
- Extract the authorization code from the URL
- Exchange the code for a Supabase session
- Create the user record in the database
- Redirect to the dashboard or show an error
Supabase Client Configuration
Client-Side Client
For browser-based authentication actions:lib/supabase/client.ts
Server-Side Client
For server actions and API routes with cookie-based session management:lib/supabase/server.ts
User Creation Flow
When a user successfully authenticates, the system creates their user record and Dodo Payments customer:actions/create-user.ts
- Retrieves the authenticated Supabase user
- Checks if a user record already exists
- Creates a Dodo Payments customer for billing
- Inserts the user record linking Supabase and Dodo IDs
Sign Out
Users can sign out from the account management section:Session Management
The starter kit uses cookie-based session management through Supabase SSR:- Sessions are stored in HTTP-only cookies
- Automatic session refresh on page navigation
- Server-side session validation for protected routes
Protected Routes
The dashboard and other protected pages check authentication status:app/dashboard/page.tsx
Environment Variables
Required environment variables for authentication:.env.example
Security Features
- OAuth 2.0: Industry-standard authentication protocol
- HTTP-Only Cookies: Session tokens are not accessible via JavaScript
- PKCE Flow: Enhanced security for the authorization code exchange
- Server-Side Validation: All protected routes validate sessions server-side
- Automatic Session Refresh: Sessions are refreshed automatically before expiration
Next Steps
Dashboard Features
Explore the authenticated user dashboard
Subscription Management
Learn about subscription features
