Next.js Discord

Discord Forum

Is it possible to pass a variable to the route handler in a custom middleware.ts file? (App router)

Unanswered
Forest bachac posted this in #help-forum
Open in Discord
Avatar
Forest bachacOP
Is it possible, in a custom middleware.ts file to pass a variable to the route handler?

Use case:
The middleware checks if the user is authenticated and if they are the route handler needs their username

5 Replies

Avatar
European sprat
You can set cookies and headers in middleware
Avatar
Forest bachacOP
could the user mess with that? like edit the header in between when the middleware sets it and the route handler checks it
Avatar
Alfonsus Ardani
no
Image
if you set it on Middleware it will be passed to the routes without any user intervention anymore