Answer the question
In order to leave comments, you need to log in
How to secure individual api routes using jwt?
I deal with express, I read this article,
Answer the question
In order to leave comments, you need to log in
you can put authorization first, but instead of sending an authorization error immediately from the middleware, this is done in the above example, do error handling in each of the protected routes.
those. The middleware only checks the presence and correctness of the token and adds the user parameter to the request (for example), and the route looks if it needs authorization and the user field is empty - it returns an error, and if authorization is not needed, then this field is not checked either.
I saw this approach just in some kind of tutorial on the passport and mongodb.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question