-
Notifications
You must be signed in to change notification settings - Fork 104
refactor: Migrate deprecated middleware to proxy as per Next.js guidelines #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
refactor: Migrate deprecated middleware to proxy as per Next.js guidelines #208
Conversation
WalkthroughThe exported handler function in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
frontend/proxy.ts (1)
8-19: Remove unused route definitions or implement routing logic.The
publicRoutes,isPublicRoute, andisProtectedRoutevariables are defined but never used. The function unconditionally returnsNextResponse.next(), making these definitions dead code.If the AuthGuard component handles all authentication (as the comment suggests), remove these unused definitions to keep the code clean. Otherwise, implement the routing logic that uses these checks.
Option 1 (if routing logic not needed): Remove dead code
export async function proxy(req: NextRequest) { - // Get the pathname - const path = req.nextUrl.pathname; - - // Define public routes that don't require authentication - const publicRoutes = ["/login", "/signup", "/"]; - const isPublicRoute = publicRoutes.includes(path); - - // Protected routes that require authentication - const isProtectedRoute = - path.startsWith("/creator") || path.startsWith("/brand"); - - // For protected routes, the AuthGuard component will handle the authentication check - // This middleware is just for basic routing logic - return NextResponse.next(); }Option 2 (if routing logic needed): Implement the checks
For example, to redirect unauthenticated users from protected routes:
export async function proxy(req: NextRequest) { // Get the pathname const path = req.nextUrl.pathname; // Define public routes that don't require authentication const publicRoutes = ["/login", "/signup", "/"]; const isPublicRoute = publicRoutes.includes(path); // Protected routes that require authentication const isProtectedRoute = path.startsWith("/creator") || path.startsWith("/brand"); - // For protected routes, the AuthGuard component will handle the authentication check - // This middleware is just for basic routing logic - + // Redirect to login if accessing protected route without auth token + if (isProtectedRoute && !req.cookies.get("auth-token")) { + return NextResponse.redirect(new URL("/login", req.url)); + } + return NextResponse.next(); }Note: Per Next.js v16 guidelines, proxy should be used for lightweight redirects and not as a full session management or authorization solution.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/proxy.ts(1 hunks)
🔇 Additional comments (2)
frontend/proxy.ts (2)
4-4: LGTM! Function rename aligns with Next.js v16 requirements.The migration correctly renames the exported function from
middlewaretoproxyas required by Next.js v16.
1-2: I'm unable to complete the verification because the repository cannot be accessed in the sandbox environment. Both direct repository cloning and GitHub CLI queries are failing due to access restrictions.However, based on the review comment provided, here is my analysis:
Rewritten Review Comment:
Verify no remaining references to deprecated middleware.ts before considering migration complete.
The imports shown (lines 1-2) are correct for the new proxy.ts pattern using Next.js v16 conventions. However, before this PR can be merged, manually verify that no other files in the codebase still:
- Import from the old
middleware.tsfile- Reference the deprecated
middlewarefunction- Contain stale middleware.ts paths in import statements
This verification is critical to ensure a complete migration from the old middleware pattern to the new proxy pattern.
|
@Saahi30 please review this and merge |
Closes #207
📝 Description
This PR migrates from the deprecated middleware file convention to the new proxy convention, following the updated Next.js v16 routing standards.
Learn more: https://nextjs.org/docs/messages/middleware-to-proxy
🔧 Changes Made
✅ Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.