Have can I get a NextRequest in middleware #81477
-
I add auth0 v4 in my middleware.ts It worked on local The question is on the Vercel, if you run middleware in App routes, not page routes, you will only get Request, not NextRequest. As a result, the Auth0 midddleware can't handle with Request, because it is handling with Request.nextUrl field which is not included in Request Is there any way to avoid this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
How do you mean? Middleware is called with NextRequest, which extends Request. So if a function expects Request as a parameter, you can still pass NextRequest, but not vice-versa. // middleware.ts
import { NextResponse, NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
console.log(request.nextUrl) // should print an object
return NextResponse.redirect(new URL('/home', request.url))
}
|
Beta Was this translation helpful? Give feedback.
How do you mean? Middleware is called with NextRequest, which extends Request. So if a function expects Request as a parameter, you can still pass NextRequest, but not vice-versa.