The OAuth redirect issue has been fixed with an improved, environment-agnostic solution.
- Line 312: Google OAuth redirect now uses
window.location.origin - Line 329: Email OTP redirect also uses
window.location.origin - Why this works: Automatically adapts to any environment without hardcoding
// Google Sign-In
redirectTo: window.location.origin
// Email OTP
emailRedirectTo: window.location.originPrevious Approach (Hardcoded):
redirectTo: import.meta.env.PROD
? 'https://illinihunt.org'
: window.location.originProblem:
- Vercel preview deployments also set
PROD=true - Preview URLs (e.g.,
https://illinihunt-abc123.vercel.app) would redirect to production - Made it impossible to test auth on preview deployments
New Approach (Dynamic):
redirectTo: window.location.originBenefits:
- ✅ Production:
https://illinihunt.org→ Works perfectly - ✅ Preview:
https://illinihunt-[hash].vercel.app→ Now works! - ✅ Local:
http://localhost:5173→ Works as before - ✅ No hardcoding: Adapts to any environment automatically
You need to configure your Supabase project to allow redirects from ALL environments:
- Go to https://supabase.com/dashboard
- Select your
illinihuntproject - Go to: Authentication → URL Configuration
Add ALL these patterns to Redirect URLs:
https://illinihunt.org
https://illinihunt.org/
https://illinihunt-*.vercel.app
https://illinihunt-*.vercel.app/
http://localhost:5173
http://localhost:5173/
Note: The wildcard pattern https://illinihunt-*.vercel.app allows ANY Vercel preview deployment to work with OAuth.
Set the Site URL to your production domain:
https://illinihunt.org
Go to: Authentication → Providers → Google
Verify:
- ✅ Google provider is enabled
- ✅ Client ID is configured
- ✅ Client Secret is configured
- ✅ Authorized redirect URIs in Google Cloud Console includes:
https://YOUR-PROJECT-REF.supabase.co/auth/v1/callback
In your Google Cloud Console OAuth settings, verify Authorized redirect URIs includes:
https://YOUR-PROJECT-REF.supabase.co/auth/v1/callback
Note: Replace YOUR-PROJECT-REF with your actual Supabase project reference ID (e.g., abcdefghijklmnop).
- Visit:
https://illinihunt.org - Click "Sign in with Google"
- Should redirect back to:
https://illinihunt.org
- Visit:
https://illinihunt-abc123.vercel.app(any preview URL) - Click "Sign in with Google"
- Should redirect back to:
https://illinihunt-abc123.vercel.app
- Visit:
http://localhost:5173 - Click "Sign in with Google"
- Should redirect back to:
http://localhost:5173
Solutions:
- Verify the wildcard pattern
https://illinihunt-*.vercel.appis in Supabase Redirect URLs - The exact URL must be added to Supabase (wildcards may not work in all Supabase versions)
- If wildcards don't work, you may need to manually add each preview URL
Solutions:
- Verify
https://YOUR-PROJECT-REF.supabase.co/auth/v1/callbackis in Google Cloud Console - Wait 5-10 minutes for Google's cache to update after adding the URI
- Make sure there are no trailing slashes or typos
Solutions:
- Ensure
http://localhost:5173(not https) is in Supabase Redirect URLs - Check that your dev server is running on port 5173
- Clear browser cookies and try again
Solutions:
- Clear browser cache/cookies
- Verify the code change is actually deployed to the preview
- Check that Supabase allows the preview URL pattern
- ✅ Code updated to use
window.location.origin - ✅ Solution merged to main branch
- ⏳ Supabase redirect URLs configured (verify in dashboard)
- ⏳ Google Cloud Console redirect URI configured
window.location.originis safe because Supabase validates against allowed redirect URLs- All redirect URLs must be explicitly whitelisted in Supabase dashboard
- Email domain restriction (
@illinois.edu) is enforced server-side - OAuth callback is handled by Supabase, not your application directly
- Always use
window.location.originfor OAuth redirects unless you have a specific reason not to - Use wildcard patterns in Supabase for preview deployments when possible
- Test auth in all environments (production, preview, local) before merging
- Keep Google Cloud Console redirect URIs minimal - only add the Supabase callback URL
- Document environment-specific configuration for future team members
- Production URL added to Supabase Redirect URLs
- Wildcard pattern for preview URLs added to Supabase
- Localhost URL added to Supabase Redirect URLs
- Google Cloud Console has Supabase callback URL
- Tested sign-in on production
- Tested sign-in on at least one preview deployment
- Tested sign-in locally
Last Updated: Post-fix by online agent (December 2025)
Solution: Dynamic window.location.origin approach