fix(middleware): restore plugin route map broken by PR #87#161
fix(middleware): restore plugin route map broken by PR #87#161seanhanca wants to merge 1 commit into
Conversation
PR #87 (c705135, "move 6 plugins to examples/") removed 7 route entries from PLUGIN_ROUTE_MAP and the auth-route redirect. This caused all affected plugins to return 404 when navigated to via sidebar links (e.g. /wallet, /gateways, /daydream), because the middleware no longer rewrote those paths to the /plugins/[pluginName] page. Changes: - Restore all removed routes: /wallet, /gateways, /orchestrators, /analytics, /leaderboard, /daydream - Add routes that were never mapped: /gateway (serviceGateway), /hello (helloWorld), /intelligent-dashboard (intelligentDashboard), /todos (todoList) - Restore auth-route redirect so logged-in users visiting /login are sent to /dashboard - Improve comments explaining the route map's purpose Root cause: PR #87 treated moving plugin source code to examples/ as removing the plugins entirely, but the plugins remain registered in the DB, built, and served via CDN. The route map is runtime infrastructure that must include all installed plugins regardless of source location. Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughMiddleware routing logic expanded with additional plugin routes (wallet, gateway, orchestrators, analytics, etc.), and authentication redirection guard implemented to redirect authenticated users away from auth-related pages to the dashboard. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 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)
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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web-next/src/middleware.ts`:
- Around line 210-215: The current check uses pathname.startsWith(route) which
causes false positives (e.g., "/login-help") when deciding whether to redirect
authenticated users; update the auth route matching in the middleware (where
authRoutes, pathname, token, and NextResponse.redirect are used) to perform
exact-or-subpath matching: treat a route as matching only if pathname === route
or pathname starts with route + '/' (or use a normalized path boundary check),
then keep the existing token check and redirect to '/dashboard' via
NextResponse.redirect(request.url) as before.
| // Redirect authenticated users away from auth pages (login/register) | ||
| if (authRoutes.some(route => pathname.startsWith(route))) { | ||
| if (token) { | ||
| return NextResponse.redirect(new URL('/dashboard', request.url)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Use exact-or-subpath matching for auth routes to avoid false redirects.
Line 211 currently uses pathname.startsWith(route), which also matches unrelated paths like /login-help or /register-success.
Suggested fix
- if (authRoutes.some(route => pathname.startsWith(route))) {
+ if (authRoutes.some(route => pathname === route || pathname.startsWith(`${route}/`))) {
if (token) {
return NextResponse.redirect(new URL('/dashboard', request.url));
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Redirect authenticated users away from auth pages (login/register) | |
| if (authRoutes.some(route => pathname.startsWith(route))) { | |
| if (token) { | |
| return NextResponse.redirect(new URL('/dashboard', request.url)); | |
| } | |
| } | |
| // Redirect authenticated users away from auth pages (login/register) | |
| if (authRoutes.some(route => pathname === route || pathname.startsWith(`${route}/`))) { | |
| if (token) { | |
| return NextResponse.redirect(new URL('/dashboard', request.url)); | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/web-next/src/middleware.ts` around lines 210 - 215, The current check
uses pathname.startsWith(route) which causes false positives (e.g.,
"/login-help") when deciding whether to redirect authenticated users; update the
auth route matching in the middleware (where authRoutes, pathname, token, and
NextResponse.redirect are used) to perform exact-or-subpath matching: treat a
route as matching only if pathname === route or pathname starts with route + '/'
(or use a normalized path boundary check), then keep the existing token check
and redirect to '/dashboard' via NextResponse.redirect(request.url) as before.
|
Closing — superseded by PR #183, which includes the same route map restoration plus additional prevention mechanisms (auto-generated plugin-routes.json, build order fix, route collision detection). |
Pull request was closed
Summary
c705135), which broke navigation for/wallet,/gateways,/orchestrators,/analytics,/leaderboard, and/daydream— all returned 404/gateway(serviceGateway),/hello(helloWorld),/intelligent-dashboard(intelligentDashboard),/todos(todoList)/loginare sent to/dashboardRoot Cause
PR #87 moved 6 plugins from
plugins/toexamples/and simultaneously removed their routes fromPLUGIN_ROUTE_MAPinmiddleware.ts. However, these plugins remain registered in the database, built into UMD bundles, and served via the CDN route. The route map is runtime infrastructure — it tells the middleware how to rewrite browser-facing URLs (e.g./gateway) to the internal plugin loader page (/plugins/serviceGateway). Without the mapping, Next.js has no matching page and returns 404.The sidebar generates
<Link href="/gateway">fromWorkflowPlugin.routes, so users clicking any plugin in the sidebar hit the 404.Timeline
examples/gateway/pr-1-foundationbranched from post-PR#87Test plan
/gatewayloads Service Gateway plugin/wallet,/daydream,/hello,/todos,/gateways,/orchestrators,/analyticsload their respective plugins/marketplaceand/dashboardstill work (they have their ownpage.tsx, not in the map)/login/loginredirects to/dashboardMade with Cursor
Summary by CodeRabbit