Overview
Authentication features:- Email/password authentication
- Google OAuth integration
- Automatic profile creation
- Session persistence
- Auto-refresh tokens
- Row Level Security (RLS) integration
Supabase Client Configuration
The authentication client is configured inpackages/app/src/integrations/supabase/client.ts:
The client includes fallback values for local development, so you can start coding without configuration.
Email Authentication
Email/password authentication is enabled by default in Supabase.Configuration
1
Local Development
No additional configuration needed. Supabase local instance has email auth enabled.
2
Production
Configure email settings in Supabase Dashboard:
- Navigate to Authentication → Settings
- Configure Email Templates (optional)
- Set up SMTP settings (optional, uses Supabase’s SMTP by default)
Email Verification
By default, Supabase requires email verification. You can disable this in:- Local:
packages/app/supabase/config.toml - Production: Supabase Dashboard → Authentication → Settings → Email Auth
packages/app/supabase/config.toml
Google OAuth
Google OAuth allows users to sign in with their Google account.Setup Instructions
1
Create Google OAuth Credentials
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Navigate to Credentials → Create Credentials → OAuth 2.0 Client ID
- Set Application Type to “Web application”
2
Configure Redirect URIs
Add authorized redirect URIs:Local development:Production:
3
Add Credentials to Environment
Add to
packages/landing/.env.local:4
Configure Supabase
Local development (Production (Supabase Dashboard):
packages/app/supabase/config.toml):- Navigate to Authentication → Providers
- Enable Google
- Add Client ID and Client Secret
Profile Creation
Automatic Profile Handling
When a user signs up, a trigger automatically creates their profile:- Extracts name from OAuth metadata (supports Google)
- Falls back to email prefix if no name provided
- Handles both
avatar_urlandpicturefields - Updates existing profiles on conflict
Profile Fields
Theprofiles table stores user information:
Session Management
Session Persistence
Sessions are automatically persisted to localStorage:Getting Current User
Auth State Changes
Row Level Security
Auth Integration
RLS policies useauth.uid() to enforce permissions:
Tenant Access
Tenant access is controlled via membership:is_tenant_member() function checks the current user’s tenant membership:
Testing Authentication
Local Test Accounts
The seed file creates test users (password:password123):
- owner@gantt.local - Tenant owner role
- editor@gantt.local - Tenant admin role
- viewer@gantt.local - Tenant member role
Sign In Flow
- Email/Password
- Google OAuth
- Sign Out
Security Best Practices
Environment Variables
Store OAuth secrets in environment variables, never in code
HTTPS Only
Always use HTTPS in production for OAuth callbacks
Row Level Security
Enable RLS on all tables to enforce access control
Token Refresh
Enable auto-refresh to prevent session expiration
Troubleshooting
Google OAuth not working locally
Google OAuth not working locally
Ensure redirect URI matches exactly:Note: Use
127.0.0.1, not localhost (Google treats them differently).Session not persisting
Session not persisting
Check that
persistSession: true is set in client configuration. Clear localStorage and try again:Profile not created automatically
Profile not created automatically
Check that the trigger exists:Re-run migrations if missing:
Additional Providers
Supabase supports many OAuth providers. To add more:- Enable provider in Supabase Dashboard or
config.toml - Add credentials to environment variables
- Update the
handle_new_user()function if provider uses different metadata fields
- GitHub
- GitLab
- Bitbucket
- Azure
- Discord
- And more…
Next Steps
Database Setup
Understand the profile and user schema
Environment Variables
Configure all required variables