Fix Auth Backend, Vercel Routing, and CORS - #5
Conversation
- Updated `vercel.json` to route `/auth/*` to backend and handle SPA fallback. - Configured robust CORS in `server.js` for local and production. - Made Google OAuth callback URL dynamic in `passport-config.js`. - Hardened `/api/auth/check-username` to enforce JSON responses and handle errors gracefully. Co-authored-by: Kaushal-15 <153284664+Kaushal-15@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe changes modernize backend configuration by introducing environment-driven defaults for Google OAuth callback URLs and CORS origins, extending username parameter sources in authentication routes, and adjusting Vercel routing to properly proxy authentication requests and serve the frontend index file. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/Backend/server.js`:
- Around line 82-84: Normalize the FRONTEND_URL before pushing into
allowedOrigins to avoid trailing-slash mismatches: read
process.env.FRONTEND_URL, trim surrounding whitespace and remove any trailing
slashes (e.g. using a regexp like .replace(/\/+$/, '')), then push the
normalized value into allowedOrigins instead of the raw value; update the code
around the allowedOrigins push that references process.env.FRONTEND_URL to use
this normalized variable.
🧹 Nitpick comments (1)
app/Backend/server.js (1)
92-103: Consider tightening the.vercel.appwildcard in production.Allowing any
*.vercel.apporigin is broader than necessary and weakens the CORS boundary. Prefer an explicit allowlist (e.g., env-driven list of known preview/prod domains) to reduce exposure.
| if (process.env.FRONTEND_URL) { | ||
| allowedOrigins.push(process.env.FRONTEND_URL); | ||
| } |
There was a problem hiding this comment.
Normalize FRONTEND_URL to avoid trailing-slash mismatches.
If FRONTEND_URL ends with /, origin comparisons will fail in production. Consider trimming.
💡 Proposed fix
if (process.env.FRONTEND_URL) {
- allowedOrigins.push(process.env.FRONTEND_URL);
+ allowedOrigins.push(process.env.FRONTEND_URL.replace(/\/$/, ''));
}🤖 Prompt for AI Agents
In `@app/Backend/server.js` around lines 82 - 84, Normalize the FRONTEND_URL
before pushing into allowedOrigins to avoid trailing-slash mismatches: read
process.env.FRONTEND_URL, trim surrounding whitespace and remove any trailing
slashes (e.g. using a regexp like .replace(/\/+$/, '')), then push the
normalized value into allowedOrigins instead of the raw value; update the code
around the allowedOrigins push that references process.env.FRONTEND_URL to use
this normalized variable.
Fixed critical production issues where auth routes were returning 404/500 and HTML responses.
vercel.json: Added routing for/authto backend and SPA catch-all.server.js: Enhanced CORS to allow localhost ports and Vercel app domains.passport-config.js: Removed hardcoded port 5000, now usesGOOGLE_CALLBACK_URLor dynamic port.routes/auth.js:check-usernamenow acceptsnameorusernameand explicitly sets content-type to JSON to prevent HTML leakage.PR created automatically by Jules for task 13648496639504608932 started by @Kaushal-15
Summary by CodeRabbit
Release Notes
Bug Fixes
New Features