Skip to content

fix(middleware): restore plugin route map broken by PR #87#161

Closed
seanhanca wants to merge 1 commit into
mainfrom
fix/restore-plugin-route-map
Closed

fix(middleware): restore plugin route map broken by PR #87#161
seanhanca wants to merge 1 commit into
mainfrom
fix/restore-plugin-route-map

Conversation

@seanhanca
Copy link
Copy Markdown
Contributor

@seanhanca seanhanca commented Feb 27, 2026

Summary

  • Restore all plugin route mappings removed by PR refactor: move 6 non-essential plugins to examples/ #87 (c705135), which broke navigation for /wallet, /gateways, /orchestrators, /analytics, /leaderboard, and /daydream — all returned 404
  • Add missing routes that were never in the map: /gateway (serviceGateway), /hello (helloWorld), /intelligent-dashboard (intelligentDashboard), /todos (todoList)
  • Restore auth-route redirect so logged-in users visiting /login are sent to /dashboard

Root Cause

PR #87 moved 6 plugins from plugins/ to examples/ and simultaneously removed their routes from PLUGIN_ROUTE_MAP in middleware.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"> from WorkflowPlugin.routes, so users clicking any plugin in the sidebar hit the 404.

Timeline

Date Event Impact
Feb 13 PR #87 merged — moved 6 plugins to examples/ Removed 7 routes from middleware + auth redirect
Feb 26 gateway/pr-1-foundation branched from post-PR#87 Inherited broken middleware
Feb 27 Testing reveals all plugin routes return 404 This fix

Test plan

  • Verify /gateway loads Service Gateway plugin
  • Verify /wallet, /daydream, /hello, /todos, /gateways, /orchestrators, /analytics load their respective plugins
  • Verify /marketplace and /dashboard still work (they have their own page.tsx, not in the map)
  • Verify unauthenticated access to plugin routes redirects to /login
  • Verify authenticated access to /login redirects to /dashboard

Made with Cursor

Summary by CodeRabbit

  • New Features
    • Enabled access to additional pages and features including wallet, gateway, orchestrators, analytics, leaderboard, and more.
    • Enhanced authentication flow: authenticated users are now automatically redirected from login and registration pages to the dashboard.

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
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 27, 2026

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

Project Deployment Actions Updated (UTC)
naap-platform Building Building Preview, Comment Feb 27, 2026 7:37am

Request Review

@github-actions github-actions Bot added scope/shell Shell app changes size/S Small PR (11-50 lines) labels Feb 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

Middleware 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

Cohort / File(s) Summary
Middleware routing and authentication
apps/web-next/src/middleware.ts
Extended PLUGIN_ROUTE_MAP with 10 new route entries for plugin handling. Added authentication guard that redirects authenticated users away from login/register pages to /dashboard, implemented in two locations within middleware flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

size/M

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(middleware): restore plugin route map broken by PR #87' directly and clearly summarizes the main change: restoring the plugin route map that was broken by a previous PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/restore-plugin-route-map

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.

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Vercel functions configuration uses incorrect paths that don't match the actual src/app/api/... directory structure, causing build failures.

Fix on Vercel

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86f8f33 and f334002.

📒 Files selected for processing (1)
  • apps/web-next/src/middleware.ts

Comment on lines +210 to +215
// 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));
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
// 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.

@seanhanca
Copy link
Copy Markdown
Contributor Author

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).

@seanhanca seanhanca closed this Mar 4, 2026
auto-merge was automatically disabled March 4, 2026 20:02

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/shell Shell app changes size/S Small PR (11-50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant