OAuth Setup
Enable users to sign in with their favorite social accounts like GitHub, Google, and more.
What is OAuth?
OAuth lets users log in using accounts they already have (like GitHub or Google) instead of creating new passwords. It's faster and more secure.
GitHub OAuth Setup
For detailed instructions, see the Supabase GitHub OAuth documentation.
1. Create GitHub OAuth App
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Fill in the details:
- Application name:
Your Onlook App
- Homepage URL:
http://localhost:3000
(or your production domain) - Authorization callback URL:
- Local development:
http://localhost:54321/auth/v1/callback
- Production:
https://your-production-domain/auth/v1/callback
- Local development:
- Application name:
- Click "Register application"
- Copy your Client ID and Client Secret
2. Configure Supabase
- Open your Supabase dashboard
- Go to Authentication → Providers
- Find GitHub and click Enable
- Paste your:
- Client ID
- Client Secret
- Click Save
3. Update Your App
Add the GitHub provider to your login page:
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(supabaseUrl, supabaseKey)
// Add GitHub login button
const signInWithGitHub = async () => {
const { error } = await supabase.auth.signInWithOAuth({
provider: 'github'
})
if (error) console.error('Error:', error)
}
Google OAuth Setup
For detailed instructions, see the Supabase Google OAuth documentation.
1. Create Google OAuth App
- Go to Google Cloud Console
- Create a new project or select existing one
- Go to APIs & Services → Credentials
- Click "Create Credentials" → "OAuth client ID"
- Choose "Web application"
- Add authorized redirect URIs:
- Local development:
http://localhost:54321/auth/v1/callback
- Production:
https://your-production-domain/auth/v1/callback
- Local development:
- Copy your Client ID and Client Secret
2. Configure Supabase
- In Supabase dashboard, go to Authentication → Providers
- Find Google and click Enable
- Paste your Client ID and Client Secret
- Click Save
3. Add to Your App
const signInWithGoogle = async () => {
const { error } = await supabase.auth.signInWithOAuth({
provider: 'google'
})
if (error) console.error('Error:', error)
}
Other Providers
Supabase supports many OAuth providers. For comprehensive setup instructions for all providers, see the Supabase Social Login documentation.
Popular providers include:
- Discord: Follow similar steps at Discord Developer Portal
- Twitter: Set up at Twitter Developer Portal
- Facebook: Configure at Facebook Developers
- Apple: Set up at Apple Developer
Note: For each provider, remember to add both local (
http://localhost:54321/auth/v1/callback
) and production (https://your-production-domain/auth/v1/callback
) redirect URIs to avoid redirect_uri_mismatch errors.
Important Notes
Environment Variables
Make sure your .env.local
has:
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
Testing
- Start your Onlook app
- Click the OAuth login button
- You should be redirected to the provider (GitHub/Google)
- After authorizing, you'll be redirected back to your app
- Check if the user is logged in
Troubleshooting
"Invalid redirect URI"
- Double-check your callback URL in the OAuth app settings
- Make sure it matches exactly:
http://localhost:54321/auth/v1/callback
"Client ID not found"
- Verify you copied the Client ID and Client Secret correctly
- Check that the OAuth provider is enabled in Supabase
"Access denied"
- Ensure your OAuth app is public (not in development mode)
- For GitHub: Check that users have access to your organization (if applicable)
Next Steps
Once OAuth is working:
- Customize the login UI
- Add user profile information
- Set up role-based access
- Configure email notifications
That's it! Your users can now sign in with their social accounts. 🎉