Skip to content

Fix middleware redirecting API routes to login page#11

Merged
WWStoryMode merged 1 commit into
mainfrom
fix/middleware-api-routes
Feb 11, 2026
Merged

Fix middleware redirecting API routes to login page#11
WWStoryMode merged 1 commit into
mainfrom
fix/middleware-api-routes

Conversation

@WWStoryMode

Copy link
Copy Markdown
Owner

Summary

  • API routes (/api/*) were being caught by the middleware's auth redirect, sending unauthenticated requests to /login instead of letting them reach their route handlers
  • API routes already have their own auth guards via guard.ts that return proper 401 {"error":"Unauthorized"} JSON responses
  • Added /api/ prefix check to isPublicRoute() so middleware passes API requests through to their own handlers

Test plan

  • DEMO_MODE=false: curl http://localhost:3000/api/orders returns 401 {"error":"Unauthorized"} (not a redirect)
  • DEMO_MODE=false: curl http://localhost:3000/vendor redirects to /login (page routes still protected)
  • DEMO_MODE=true: All routes accessible without auth (no regression)
  • npm run build passes

🤖 Generated with Claude Code

API routes have their own auth guards via guard.ts that return proper
401 JSON responses. The middleware was intercepting these requests first
and redirecting them to /login, which is incorrect for API consumers.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vercel

vercel Bot commented Feb 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
project-firefly Ready Ready Preview, Comment Feb 11, 2026 3:54pm

@WWStoryMode
WWStoryMode merged commit a369ef4 into main Feb 11, 2026
3 checks passed
@WWStoryMode
WWStoryMode deleted the fix/middleware-api-routes branch February 11, 2026 15:54
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.

1 participant