routes order when using nodejs

does arrangement or order of routes matter in nodejs when building api's because I currently have my routes some with jwt tokens and others without tokens but when I try to access routes without tokens insomnia asks that add a jtw token, is that a bug or should I re arrange my routes?
4 Replies
Joao
Joao13mo ago
It does, routes are processed from top to bottom so if you added your auth middleware somewhere in between you'll run into this sort of issues.
kalanzi
kalanzi13mo ago
Alright thank you,so I need to put all my routes that dont need auth middlware first?
Joao
Joao13mo ago
Yes, or define the auth middleware in the route itself. That way you don't have to worry about ordering them, for this use case anyway.
kalanzi
kalanzi13mo ago
Thanks @Joao
Want results from more Discord servers?
Add your server