Skip to content

fix(auth): resolve Vercel 504 timeout by optimizing middleware queries#99

Merged
EmiyaKiritsugu3 merged 2 commits into
mainfrom
fix/middleware-timeout
May 6, 2026
Merged

fix(auth): resolve Vercel 504 timeout by optimizing middleware queries#99
EmiyaKiritsugu3 merged 2 commits into
mainfrom
fix/middleware-timeout

Conversation

@EmiyaKiritsugu3
Copy link
Copy Markdown
Owner

Description

This PR resolves the MIDDLEWARE_INVOCATION_TIMEOUT (504 Gateway Timeout) on Vercel production by optimizing the auth middleware logic.

🔍 RCA

The middleware was performing up to 3 sequential Supabase network calls per protected request. Given the cross-region latency between Vercel Edge and the Supabase DB (Brazil), this often exceeded the Edge Runtime execution limit.

⚡ Fix

Consolidated the employee existence check and role fetching into a single query.

  • Reduced network round-trips by 50% for restricted routes.
  • Eliminated redundant select('id') query.

Type of Change

  • perf — Performance improvement
  • fix — Bug fix

Related Documents

  • Incident Log: docs/process/sentinel-log.md

Checklist

  • npm run typecheck — zero errors
  • npm run lint — zero errors
  • npm run format:check — no formatting issues
  • npm test src/lib/auth.test.ts — all tests pass
  • Documentation updated (Sentinel Log)

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 6, 2026

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

Project Deployment Actions Updated (UTC)
smartmanagementsystem Ready Ready Preview, Comment May 6, 2026 1:48pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@EmiyaKiritsugu3 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 14 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1f147102-e209-4f4d-a529-02d4b7a9d53f

📥 Commits

Reviewing files that changed from the base of the PR and between 25d7f0f and b0df206.

📒 Files selected for processing (2)
  • docs/process/sentinel-log.md
  • src/utils/supabase/middleware.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/middleware-timeout

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@EmiyaKiritsugu3 EmiyaKiritsugu3 merged commit b0df206 into main May 6, 2026
4 of 5 checks passed
@EmiyaKiritsugu3 EmiyaKiritsugu3 deleted the fix/middleware-timeout branch May 6, 2026 13:44
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