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
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
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
Use case:
The middleware checks if the user is authenticated and if they are the route handler needs their username
5 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
European sprat
You can set cookies and headers in middleware
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
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](https://cdn.discordapp.com/avatars/194128415954173952/708a8637ada505b6b7a85972807d9dca.webp?size=256)
Alfonsus Ardani
no
![Image](https://cdn.discordapp.com/attachments/1133937798634799114/1133978902084194354/image.png)
if you set it on Middleware it will be passed to the routes without any user intervention anymore