Google OAuth Setup Guide
This guide walks you through setting up Google OAuth authentication for Supershyft OS.
Implementation Status
✅ Backend OAuth routes implemented ✅ JWT session management implemented ✅ Auth middleware updated for session cookies ✅ Frontend login page updated with Google button ✅ Logout functionality added ✅ Dev mode compatibility maintained
Prerequisites
- Google Cloud Console account
- Access to Supershyft OS codebase
- Wrangler CLI installed for production secrets
Step 1: Google Cloud Console Setup
1.1 Create/Select Project
- Go to Google Cloud Console
- Create a new project or select existing project
- Name it something like "Supershyft OS" or "Supershyft Authentication"
1.2 Enable Google Identity API
- Navigate to APIs & Services → Library
- Search for "Google+ API" or "Google Identity Services API"
- Click Enable
1.3 Configure OAuth Consent Screen
- Navigate to APIs & Services → OAuth consent screen
- Select Internal (if using Google Workspace) or External
- Fill in application details:
- App name: Supershyft OS
- User support email: Your email
- Developer contact email: Your email
- Click Save and Continue
- Skip scopes (default scopes are sufficient)
- Add test users if using External consent:
- Add all
@capcoib.comusers who need access - Add
louis.decuypere@gmail.com
- Add all
- Click Save and Continue
1.4 Create OAuth 2.0 Credentials
- Navigate to APIs & Services → Credentials
- Click + CREATE CREDENTIALS → OAuth client ID
- Select Web application
- Configure:
- Name: Supershyft OS Web Client
- Authorized JavaScript origins:
http://localhost:5173(development)http://localhost:8787(API dev)https://os.supershyft.capital(production)https://api.supershyft.capital(production API)
- Authorized redirect URIs:
http://localhost:8787/api/auth/google(development)https://api.supershyft.capital/api/auth/google(production)
- Click Create
- Copy the Client ID and Client Secret (you'll need these next)
Step 2: Configure Local Development
2.1 Update .dev.vars
The file apps/api-worker/.dev.vars has been created with placeholders. Update it with your credentials:
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
FRONTEND_URL=http://localhost:5173
# JWT Secret (already generated)
JWT_SECRET=Fi1UACq0Y22w1KcjOpovhwKJnlwJH9uGIGHLnTz74ok=Replace:
GOOGLE_CLIENT_IDwith the Client ID from Google ConsoleGOOGLE_CLIENT_SECRETwith the Client Secret from Google Console
2.2 Test Locally
Start the API worker:
bashpnpm dev:apiStart the frontend:
bashpnpm dev:webVisit
http://localhost:5173Click "Sign in with Google"
You should be redirected to Google's OAuth consent screen
After authorizing, you'll be redirected back to
/homeCheck that your email is displayed in the sidebar
2.3 Verify Session
- Check browser dev tools → Application → Cookies
- You should see a
sessioncookie (HttpOnly, SameSite=Lax) - The cookie contains your JWT session token
2.4 Test Logout
- Click your profile in the sidebar
- Click Sign out
- You should be redirected to the login page
- Session cookie should be cleared
Step 3: Configure Production
3.1 Set Production Secrets
Use Wrangler CLI to set secrets for the production API worker:
cd apps/api-worker
# Set Google OAuth credentials
wrangler secret put GOOGLE_CLIENT_ID
# Paste your Client ID
wrangler secret put GOOGLE_CLIENT_SECRET
# Paste your Client Secret
# Set JWT secret (use a new one for production!)
wrangler secret put JWT_SECRET
# Generate new: openssl rand -base64 32
# Set frontend URL
wrangler secret put FRONTEND_URL
# Enter: https://os.supershyft.capital3.2 Deploy API Worker
pnpm deploy:api3.3 Deploy Frontend
Frontend auto-deploys via Cloudflare Pages on git push:
git add .
git commit -m "feat: Add Google OAuth authentication"
git push origin main3.4 Test Production
- Visit
https://os.supershyft.capital - Click Sign in with Google
- Authorize with your
@capcoib.comorlouis.decuypere@gmail.comaccount - Verify you're redirected to
/home - Test logout functionality
Step 4: Security Checklist
- [ ] Google OAuth consent screen configured correctly
- [ ] Only authorized domains can access (
capcoib.com,louis.decuypere@gmail.com) - [ ] Redirect URIs match exactly (no trailing slashes)
- [ ] Production uses HTTPS for all OAuth flows
- [ ] JWT secret is different in production vs development
- [ ] Session cookies are HttpOnly and Secure (in production)
- [ ] Dev mode still works with
X-User-Emailheader
Architecture Overview
Authentication Flow
1. User clicks "Sign in with Google"
→ Redirects to /api/auth/google
2. API redirects to Google OAuth consent screen
→ Google handles authentication
3. Google redirects back to /api/auth/google with auth code
→ API validates email domain
→ Creates JWT session token
→ Sets session cookie (HttpOnly, 7-day expiry)
→ Redirects to /home
4. Subsequent requests include session cookie
→ Auth middleware extracts email from JWT
→ User is authenticated for all API calls
5. User clicks "Sign out"
→ POST /api/auth/logout
→ Clears session cookie
→ Redirects to login pageEmail Authorization
Only the following emails can log in:
louis.decuypere@gmail.com(exact match)- Any
@capcoib.comemail (domain match)
Unauthorized emails see an error message after Google OAuth.
Session Management
- Token Type: JWT (JSON Web Token)
- Storage: HttpOnly cookie named
session - Expiry: 7 days
- Refresh: Not implemented (user must re-login after 7 days)
- Security: HttpOnly, SameSite=Lax, Secure (production only)
Dev Mode Compatibility
Dev mode continues to work as before:
X-User-Emailheader takes precedence- No OAuth required in development
- LocalStorage-based user switching still functional
API Endpoints
Public Endpoints (No Auth Required)
GET /api/auth/google- Initiates OAuth flowGET /api/auth/status- Health check for auth system
Protected Endpoints (Auth Required)
GET /api/auth/me- Returns current user infoPOST /api/auth/logout- Clears session- All other
/api/*routes require authentication
Troubleshooting
Issue: "redirect_uri_mismatch" error
Solution: Ensure the redirect URI in Google Console matches EXACTLY:
- Dev:
http://localhost:8787/api/auth/google - Prod:
https://api.supershyft.capital/api/auth/google
No trailing slashes, exact protocol (http vs https).
Issue: "unauthorized_email" error
Solution:
- Check that your email is
@capcoib.comorlouis.decuypere@gmail.com - Update
apps/api-worker/src/routes/auth.tsto add more emails/domains
Issue: Session cookie not being set
Solution:
- Check browser dev tools → Network → Response headers
- Look for
Set-Cookieheader - Ensure CORS is allowing credentials (
credentials: true) - Verify domain matches (
.supershyft.capitalfor production)
Issue: "JWT_SECRET environment variable is required"
Solution:
- Check
.dev.varsfile exists and hasJWT_SECRET - For production, run
wrangler secret put JWT_SECRET - Restart API worker after adding secret
Issue: Dev mode stops working
Solution:
- Dev mode should still work with
X-User-Emailheader - Check that shared API client is sending the header
- Verify auth middleware checks dev header FIRST (before OAuth)
Files Modified
Backend
apps/api-worker/src/routes/auth.ts(new) - OAuth routesapps/api-worker/src/lib/jwt.ts(new) - JWT utilitiesapps/api-worker/src/middleware/auth.ts- Session cookie supportapps/api-worker/src/index.ts- Register auth routesapps/api-worker/.dev.vars- OAuth environment variables
Frontend
apps/web/src/views/Login.vue- Google sign-in buttonapps/web/src/composables/useUser.ts- OAuth flow + logoutapps/web/src/ui/AppShell.vue- Logout button
Documentation
docs/development/GOOGLE_OAUTH_SETUP.md(this file)
Next Steps
- ✅ Complete Google Cloud Console setup
- ✅ Update
.dev.varswith your credentials - ✅ Test locally (dev environment)
- ⬜ Set production secrets via Wrangler
- ⬜ Deploy to production
- ⬜ Test production OAuth flow
- ⬜ Update
CLAUDE.mdwith OAuth documentation
Support
If you encounter issues:
- Check browser console for errors
- Check API worker logs:
wrangler tail - Verify Google Cloud Console configuration
- Check CORS settings in
apps/api-worker/src/index.ts
Last Updated: 2025-10-20 Status: Implementation complete, ready for Google Cloud setup