How can I modify the request object in Next.js middleware file?
I have seen this question but it does not answer my question.
I have a middleware file that looks like below:
// middleware.js
export function middleware(request: NextRequest) {
req.name = "foo";
//If I console.log req.name I see it is equal to foo.
console.log(req.name) // logs "foo"
}
Then I have an api route like below
// pages/api/hello.js
export default async function handler(req, res) {
console.log( req.name ) //logs undefined
// what can I do so that I can access the new properties
// I put in the req object in the middlware file here?
}