This guide walks you through setting up GitHub OAuth for authentication with Supabase.
- Overview
- Prerequisites
- GitHub OAuth App Setup
- Supabase Configuration
- Testing
- Production Deployment
- Troubleshooting
GitHub OAuth allows users to sign in to your application using their GitHub account. This is particularly useful for:
- Developer-focused apps - Your users likely already have GitHub accounts
- Seamless UX - One-click sign in
- Access to GitHub data - Optionally access repos, gists, etc.
User clicks "Sign in with GitHub"
↓
Redirect to GitHub authorization page
↓
User grants permission
↓
GitHub redirects to Supabase callback URL
↓
Supabase creates/updates user and session
↓
Redirect to your application
- GitHub Account - Any GitHub account can create OAuth apps
- Supabase Project - See Supabase Setup Guide
- Your Supabase callback URL (format:
https://xxxxx.supabase.co/auth/v1/callback)
- Go to GitHub and sign in
- Click your profile picture (top-right) → Settings
- Scroll down to Developer settings (bottom of left sidebar)
- Click OAuth Apps
Or go directly to: github.com/settings/developers
-
Click New OAuth App (or Register a new application)
-
Fill in the application details:
| Field | Value |
|---|---|
| Application name | Your app name (e.g., myimageupscaler.com) |
| Homepage URL | Your app's homepage (e.g., https://myimageupscaler.com) |
| Application description | (Optional) Brief description |
| Authorization callback URL | Your Supabase callback URL |
Before filling in the callback URL, get it from Supabase:
- Go to Supabase Dashboard
- Select your project
- Navigate to Authentication → Providers
- Click on GitHub
- Copy the Callback URL shown (format:
https://xxxxx.supabase.co/auth/v1/callback)
- Paste the Supabase callback URL in Authorization callback URL
- Click Register application
After registration, you'll see your app's settings page:
- Copy the Client ID (displayed on the page)
- Click Generate a new client secret
- Copy the Client Secret immediately (it won't be shown again!)
Client ID: Iv1.xxxxxxxxxxxxxxxx
Client Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Warning: Store the Client Secret securely. If you lose it, you'll need to generate a new one.
- Click Upload new logo
- Upload a square image (recommended: 512x512 px)
- This logo appears on the GitHub authorization page
- Go to Supabase Dashboard
- Select your project
- Navigate to Authentication → Providers
- Click on GitHub to expand
- Toggle Enable GitHub provider to ON
- Paste your Client ID from GitHub
- Paste your Client Secret from GitHub
- Click Save
- Navigate to Authentication → URL Configuration
- Set Site URL to your production URL:
https://yourdomain.com - Add Redirect URLs for all environments:
http://localhost:3000/** http://localhost:8788/** https://yourdomain.com/** https://www.yourdomain.com/** https://your-project.pages.dev/**
-
Start your development server:
yarn dev
-
Navigate to your login page
-
Click "Sign in with GitHub"
-
Authorize the app on GitHub's authorization page
-
You should be redirected back to your app, authenticated
Check that the user was created in Supabase:
-- In Supabase SQL Editor
SELECT id, email, raw_user_meta_data
FROM auth.users
WHERE raw_user_meta_data->>'provider_id' IS NOT NULL;The raw_user_meta_data will contain:
user_name- GitHub usernameavatar_url- Profile picture URLfull_name- Display name (if set)
- Go to GitHub Developer Settings
- Click on your OAuth app
- Update Homepage URL to production URL
- The Authorization callback URL should already be your Supabase URL (no change needed)
- Update Homepage URL in GitHub OAuth app
- Update Supabase Site URL to production domain
- Add production URLs to Supabase Redirect URLs
- Test OAuth flow on production
- (Optional) Add app logo for better branding
For production apps, consider creating the OAuth app under a GitHub Organization:
- Go to your organization's settings
- Navigate to Developer settings → OAuth Apps
- Create the app there
Benefits:
- Multiple maintainers can manage the app
- Professional appearance (org name shown in authorization)
- Centralized credential management
Cause: Callback URL mismatch between GitHub and Supabase.
Solution:
- Copy the exact callback URL from Supabase → Authentication → Providers → GitHub
- Update the Authorization callback URL in GitHub OAuth app settings
- Ensure no trailing slash differences
Cause: GitHub suspended the OAuth app (usually due to policy violations).
Solution:
- Check your email for notices from GitHub
- Review GitHub's OAuth app policies
- Contact GitHub support if needed
Cause: Profile trigger not working.
Solution:
- Check
handle_new_usertrigger exists (see Supabase Setup) - Verify user exists in
auth.users - Manually create profile:
INSERT INTO profiles (id, email, full_name, avatar_url) SELECT id, email, raw_user_meta_data->>'full_name', raw_user_meta_data->>'avatar_url' FROM auth.users WHERE id = 'user-uuid';
Cause: Invalid or expired Client Secret.
Solution:
- Generate a new Client Secret in GitHub OAuth app settings
- Update the secret in Supabase → Authentication → Providers → GitHub
- Note: Old secret is invalidated immediately
Cause: User has email set to private on GitHub.
Solution:
GitHub provides a fallback email format: {id}+{username}@users.noreply.github.com
To request email scope explicitly, you can modify the auth call:
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
options: {
scopes: 'user:email',
},
});Cause: Too many OAuth requests from your app.
Solution:
- Implement proper session management (don't re-auth unnecessarily)
- Use refresh tokens instead of new OAuth flows
- Consider caching user data
By default, GitHub OAuth provides basic profile info. For additional access:
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
options: {
scopes: 'read:user user:email repo',
redirectTo: `${window.location.origin}/auth/callback`,
},
});Common scopes:
| Scope | Access |
|---|---|
read:user |
Read user profile data |
user:email |
Read user email addresses |
repo |
Full access to repositories |
public_repo |
Access to public repositories only |
For more advanced use cases, consider a GitHub App:
| Feature | OAuth App | GitHub App |
|---|---|---|
| Rate limits | Lower | Higher |
| Permissions | User-level | Fine-grained |
| Installation | Per-user | Per-org/repo |
| Best for | Simple auth | GitHub integrations |
- Keep Client Secret secure - Never commit to version control
- Use HTTPS - Required for production OAuth
- Validate state parameter - Supabase handles this automatically
- Limit scopes - Only request what you need
- Rotate secrets periodically - Generate new secrets and update Supabase