11 KiB
BetterAuth OAuth Configuration - Admin Setup Guide
Overview
Your application uses BetterAuth framework for OAuth authentication. OAuth providers (Google, GitHub, Facebook, Discord) can be:
- ✅ Configured via
/admin/setuppage (recommended) - ✅ Enabled/disabled dynamically without server restart
- ✅ Credentials saved to
data/system-config.json
Quick Start
1. Access Admin Setup Page
http://localhost:3001/admin/setup
2. Scroll to "OAuth Providers (BetterAuth)" Section
You'll see 4 provider cards:
- 🐙 GitHub
- 💬 Discord
3. For Each Provider You Want to Enable:
- Check the "Enable [Provider] OAuth" checkbox
- Enter Client ID and Client Secret
- Click "💾 Save Settings"
Getting OAuth Credentials
🔍 Google OAuth Setup
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Click "Select a Project" → "New Project"
- Enter project name:
estate-platform - Click "Create"
Step 2: Enable OAuth 2.0
- In sidebar, go to APIs & Services → Library
- Search for "Google+ API"
- Click it and click "Enable"
Step 3: Create OAuth Credentials
- Go to APIs & Services → Credentials
- Click "Create Credentials" → "OAuth client ID"
- Choose application type: Web application
- Name it:
estate-platform-web
Step 4: Configure Redirect URIs
In the "Authorized redirect URIs" section, add:
http://localhost:3001/auth/google/callback
For production, also add:
https://yourdomain.com/auth/google/callback
Step 5: Copy Credentials
- Click your created credential
- Copy the Client ID and Client Secret
- Paste them in the Google section on
/admin/setup
🐙 GitHub OAuth Setup
Step 1: Register OAuth Application
- Go to GitHub Developer Settings
- Click "OAuth Apps" → "New OAuth App"
- Fill in:
- Application name:
estate-platform - Homepage URL:
http://localhost:3001 - Authorization callback URL:
http://localhost:3001/auth/github/callback
- Application name:
Step 2: Copy Credentials
- You'll see Client ID immediately
- Click "Generate a new client secret"
- Copy both Client ID and Client Secret
- Paste them in the GitHub section on
/admin/setup
For Production:
Update the callback URL to:
https://yourdomain.com/auth/github/callback
👍 Facebook OAuth Setup
Step 1: Create Facebook App
- Go to Facebook Developers
- Click "My Apps" → "Create App"
- Choose app type: Consumer
- Fill in app details:
- App Name:
estate-platform - App Contact Email: your-email@example.com
- Purpose: Select appropriate category
- App Name:
Step 2: Add Facebook Login Product
- In app dashboard, click "Add Product"
- Find "Facebook Login" and click "Set Up"
- Choose platform: Web
- Skip to "Settings"
Step 3: Configure OAuth Redirect URLs
-
In Facebook Login → Settings
-
Under "Valid OAuth Redirect URIs", add:
http://localhost:3001/auth/facebook/callbackFor production:
https://yourdomain.com/auth/facebook/callback
Step 4: Copy Credentials
- Go to Settings → Basic
- Copy App ID (use as Client ID)
- Copy App Secret (use as Client Secret)
- Paste them in the Facebook section on
/admin/setup
💬 Discord OAuth Setup
Step 1: Create Discord Application
- Go to Discord Developer Portal
- Click "New Application"
- Enter name:
estate-platform - Accept terms and create
Step 2: Generate OAuth Credentials
- In sidebar, click "OAuth2"
- Under CLIENT INFORMATION, you'll see:
- CLIENT ID (copy this)
- Click "Reset Secret" to get CLIENT SECRET (copy this)
Step 3: Set Redirect URI
- Under REDIRECTS, click "Add Redirect"
- Enter:
http://localhost:3001/auth/discord/callback - Click "Save Changes"
For production:
https://yourdomain.com/auth/discord/callback
Step 4: Paste Credentials
Copy Client ID and Client Secret to Discord section on /admin/setup
Configuration via Admin Setup Page
Location
/admin/setup
What You'll See
A clean 2x2 grid of OAuth provider cards:
┌─────────────────────────┬─────────────────────────┐
│ 🔍 Google │ 🐙 GitHub │
│ │ │
│ ☐ Enable Google OAuth │ ☐ Enable GitHub OAuth │
│ [Client ID input] │ [Client ID input] │
│ [Client Secret input] │ [Client Secret input] │
└─────────────────────────┴─────────────────────────┘
┌─────────────────────────┬─────────────────────────┐
│ 👍 Facebook │ 💬 Discord │
│ │ │
│ ☐ Enable Facebook OAuth │ ☐ Enable Discord OAuth │
│ [App ID input] │ [Client ID input] │
│ [App Secret input] │ [Client Secret input] │
└─────────────────────────┴─────────────────────────┘
How to Configure
For Each Provider:
- Check the checkbox to enable OAuth for that provider
- Enter Client ID - The public identifier from the provider
- Enter Client Secret - Keep this secret! Only use in secure environments
- Click "💾 Save Settings" at the bottom
What Happens After Saving
- Credentials are saved to
data/system-config.json - BetterAuth automatically picks up the new configuration
- OAuth buttons appear on login page for enabled providers
- Users can immediately use OAuth sign-in
Testing OAuth Flow
Step 1: Enable at Least One Provider
Go to /admin/setup and enable Google (easiest to test)
Step 2: Visit Login Page
Go to http://localhost:3001 and click login button
Step 3: Click OAuth Button
Click "Continue with Google" button
Step 4: Verify Redirect
You should be redirected to Google's login page:
https://accounts.google.com/o/oauth2/v2/auth?client_id=...
Step 5: Complete Authentication
- Sign in with your Google account
- Grant permissions if prompted
- You should be redirected back and logged in
Troubleshooting
OAuth Buttons Don't Show
Problem: No OAuth buttons on login page even after configuration Solutions:
- Clear browser cache:
Ctrl+Shift+Delete - Refresh page:
Ctrl+R - Check admin setup page - provider might not be enabled
- Verify JSON syntax in system-config.json
"Invalid Client ID" Error
Problem: Error when trying to use OAuth Solutions:
- Verify Client ID is correct - copy from developer console again
- Check spelling - no extra spaces
- Ensure provider is enabled (checkbox checked)
- Restart server:
npm run dev
Redirect URI Mismatch
Problem: Provider says "redirect_uri mismatch" Solutions:
- Verify exact callback URL in provider console:
- Development:
http://localhost:3001/auth/{provider}/callback - Production:
https://yourdomain.com/auth/{provider}/callback
- Development:
- Check for typos - URLs are case-sensitive
- Don't include query parameters
- Save changes in provider console
"Invalid Client Secret"
Problem: Error during OAuth callback Solutions:
- Double-check Client Secret - copy from provider console again
- Ensure no extra spaces before/after
- Verify it's not Client ID instead
- Some providers show secret only once - regenerate if lost
Provider Not Responding
Problem: Redirect hangs or takes forever Solutions:
- Check internet connection
- Verify provider status page - provider may be down
- Check firewall - may be blocking external requests
- Check
BETTER_AUTH_SECRETis set in .env
Environment Variables (Optional)
Instead of using admin setup page, you can set environment variables in .env:
# Google OAuth
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
# GitHub OAuth
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret
# Facebook OAuth
FACEBOOK_CLIENT_ID=your-app-id
FACEBOOK_CLIENT_SECRET=your-app-secret
# Discord OAuth
DISCORD_CLIENT_ID=your-client-id
DISCORD_CLIENT_SECRET=your-client-secret
# BetterAuth Secret (REQUIRED)
BETTER_AUTH_SECRET=your-32-character-secret
Note: Admin setup page takes precedence over environment variables
Production Deployment
Important Security Notes:
- Never commit credentials to Git
- Use environment variables in production (not system-config.json)
- Use HTTPS for all callback URLs
- Enable CSRF protection (currently disabled for development)
- Rotate secrets regularly
Callback URL Format:
https://yourdomain.com/auth/{provider}/callback
Replace with your actual domain for each provider!
Update Provider Consoles:
- Google Cloud Console
- GitHub OAuth App Settings
- Facebook App Settings
- Discord Developer Portal
All must have production URL as redirect URI.
File Locations
Configuration Storage
data/system-config.json
Example structure:
{
"oauth": {
"google": {
"enabled": true,
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET"
},
"github": {
"enabled": true,
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET"
},
"facebook": {
"enabled": true,
"clientId": "YOUR_APP_ID",
"clientSecret": "YOUR_APP_SECRET"
},
"discord": {
"enabled": true,
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET"
}
}
}
BetterAuth Configuration
lib/auth.ts
Admin Setup Page
app/admin/setup/page.tsx
OAuth Callback Routes
app/auth/google/callback/route.ts
app/auth/github/callback/route.ts
app/auth/facebook/callback/route.ts
app/auth/discord/callback/route.ts
Frontend Login Modal
components/auth/AuthModal.tsx
Summary
✅ OAuth is configured via BetterAuth framework
✅ Admin setup page at /admin/setup for easy configuration
✅ Support for 4 major OAuth providers
✅ Enable/disable providers without server restart
✅ Credentials saved in system-config.json
For detailed setup of each provider, follow the step-by-step guides above!