Skip to content

Fix CORS authentication failures and improve error handling - #1

Draft
rb-369 with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-cors-policy-error
Draft

Fix CORS authentication failures and improve error handling#1
rb-369 with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-cors-policy-error

Conversation

Copilot AI commented Feb 15, 2026

Copy link
Copy Markdown

Frontend authentication requests (/api/user/auth, /api/user/login, /api/user/google-oauth) blocked by CORS policy. Root cause: missing cookie headers in CORS config and no preflight handling.

Changes

CORS Configuration (server/index.js)

  • Dynamic origin validation (handles no-origin requests)
  • Added Cookie to allowedHeaders, Set-Cookie to exposedHeaders
  • Explicit app.options("*") for preflight requests
const corsOptions = {
    origin: function (origin, callback) {
        const allowedOrigins = ["https://smart-task-manager-sl4a.vercel.app", "http://localhost:5173", "http://localhost:5000"];
        if (!origin || allowedOrigins.indexOf(origin) !== -1) {
            callback(null, true);
        } else {
            callback(new Error("Not allowed by CORS"));
        }
    },
    allowedHeaders: ["Content-Type", "Authorization", "Cookie"],
    exposedHeaders: ["Set-Cookie"],
    preflightContinue: false
};

app.use(cors(corsOptions));
app.options("*", cors(corsOptions));

Error Handling

  • Redis error listeners prevent crashes on connection failures
  • Global error handler for uncaught errors
  • Consistent logger.info/warn/error throughout

Observability

  • /health endpoint for monitoring

Documentation

  • CORS_FIX_EXPLANATION.md - technical details and troubleshooting
  • DEPLOYMENT_GUIDE.md - deployment checklist
  • SUMMARY.md - overview

Deployment Note
Requires NODE_ENV=production in Railway for correct cookie settings (secure: true, sameSite: "none").


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Feb 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
smart-task-manager Error Error Feb 15, 2026 0:51am
smart-task-manager-mfnq Error Error Feb 15, 2026 0:51am
smart-task-manager-sl4a Ready Ready Preview, Comment Feb 15, 2026 0:51am

…t handling

Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Co-authored-by: rb-369 <219688123+rb-369@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CORS policy error for user authentication Fix CORS policy errors and improve error handling for authentication endpoints Feb 15, 2026
Copilot AI requested a review from rb-369 February 15, 2026 12:36
Copilot AI changed the title Fix CORS policy errors and improve error handling for authentication endpoints Fix CORS policy errors blocking authentication endpoints Feb 15, 2026
Copilot stopped work on behalf of rb-369 due to an error February 15, 2026 12:46
Copilot AI changed the title Fix CORS policy errors blocking authentication endpoints Fix CORS authentication failures and improve error handling Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants