import { NextRequest, NextResponse } from "next/server"; import { verifyToken } from…
- User
import { NextRequest, NextResponse } from "next/server"; import { verifyToken } from "@/src/helper/verifyToken"; import { publicRoutes } from "@/src/constants/middleware";
export default async function middleware(request: NextRequest) { try { const pathname = request.nextUrl.pathname; console.log("Middleware executing for path:", pathname); //for bypass the middleware for routes // if (pathname) return NextResponse.next(); if (publicRoutes(pathname)) { console.log("Path is public, continuing..."); return NextResponse.next(); }
const token = request.headers.get("authorization")?.split(" ")[1] || ""; console.log("Token extracted:", token);
if (!token) { console.log("No token found, redirecting to login..."); return NextResponse.redirect(new URL("/login", request.url)); }
const decodedToken = verifyToken(token); if (!decodedToken) { console.log("Invalid token, redirecting to login..."); return NextResponse.redirect(new URL("/login", request.url)); }
console.log("Token verified, allowing access to protected route"); return NextResponse.next(); } catch (error) { console.error("Error in middleware:", error); return NextResponse.redirect(new URL("/login", request.url)); } }
export const config = { matcher: [ /*
- Match all request paths except for the ones starting with:
-
- api (API routes)
-
- _next/static (static files)
-
- _next/image (image optimization files)
-
- favicon.ico (favicon file)
-
- assets in the public folder / "/((?!api|_next/static|_next/image|favicon.ico|public).)", ], }; @workspace styles of my app is corrupted cause of matcher
- Assistant
It sounds like the matcher in your Next.js middleware configuration is overly restrictive, potentially blocking access to certain static files or resources necessary for the styling of your application. This is a common issue when defining middleware paths.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.