Skip to content

fix: migrate middleware.ts → proxy.ts to fix 500 MIDDLEWARE_INVOCATION_FAILED#72

Draft
DealPatrol wants to merge 1 commit into
mainfrom
claude/repofuse-issue-BLCE7
Draft

fix: migrate middleware.ts → proxy.ts to fix 500 MIDDLEWARE_INVOCATION_FAILED#72
DealPatrol wants to merge 1 commit into
mainfrom
claude/repofuse-issue-BLCE7

Conversation

@DealPatrol

Copy link
Copy Markdown
Owner

Summary

  • Root cause: Next.js 16 deprecated the middleware file convention in favour of proxy. The old middleware.ts was still being compiled but was failing at runtime with MIDDLEWARE_INVOCATION_FAILED on every request, producing the 500 error visible on repofuse.com.
  • Fix 1: Rename middleware.tsproxy.ts (the file Next.js 16 actually runs).
  • Fix 2: Return NextResponse.next() explicitly instead of bare return — returning undefined is not a valid Edge runtime response and triggers the 500.
  • Fix 3: Wrap auth.protect() in its own try/catch so a Clerk auth failure redirects gracefully instead of propagating as an unhandled exception.
  • Fix 4: Outer try/catch on the whole handler so any unexpected error redirects to /?error=middleware_error rather than surfacing as a 500.

The auth logic itself (Clerk when configured, legacy GitHub OAuth cookies otherwise) is unchanged.

Test plan

  • Verify the Vercel build warning about middleware deprecation is gone
  • Visit repofuse.com — should load without 500 error
  • Unauthenticated visit to /dashboard → redirects to /?error=auth_required
  • Authenticated visit to /dashboard → loads normally
  • Public pages (/, /pricing, etc.) → load without errors

https://claude.ai/code/session_018w2VTF3yhVhavRJ8rTVWaV


Generated by Claude Code

Next.js 16 deprecated the `middleware` file convention in favour of `proxy`.
The deprecated `middleware.ts` was causing MIDDLEWARE_INVOCATION_FAILED 500
errors on every request hitting repofuse.com.

Changes:
- Rename middleware.ts → proxy.ts (required by Next.js 16)
- Return NextResponse.next() explicitly instead of bare `return` (undefined
  is not a valid response in the Edge runtime and triggers the 500)
- Wrap auth.protect() in its own try/catch to redirect gracefully on Clerk
  auth failures rather than surfacing an unhandled exception
- Add outer try/catch so any unexpected error redirects cleanly instead of
  propagating as a 500

https://claude.ai/code/session_018w2VTF3yhVhavRJ8rTVWaV
@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
repo-app-architect Ready Ready Preview, Comment Jun 2, 2026 3:16am
repofuse Ready Ready Preview, Comment, Open in v0 Jun 2, 2026 3:16am
v0-repo-app-architect Ready Ready Preview, Comment, Open in v0 Jun 2, 2026 3:16am

@supabase

supabase Bot commented Jun 2, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project bpjftwoiosftvjvxpovz because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

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