r/FastAPI • u/GamersPlane • Nov 27 '24
Question Conditional middleware/passing params to middleware
From how middlewares are structured, it seems like before call_next(request), the middleware has no connection to the route being called. What I'd like to do is set up a middleware that authenticates a user token, and if its invalid, throw an error, unless the route has a flat/decorator/something to mark that it's public.
Can I pass info to a middleware on a route by route basis? Or is there a different mechanism I should use here?
4
Upvotes
View all comments
Show parent comment
1
u/GamersPlane Nov 27 '24
Uh... That's the opposite of what I want to do. I already know I can set up a dependency on each route. The question is if I can pass something on certain routes.