I am trying to use express nodejs and JWT. Here is the source code of what I've been through: link.
I protect all routes, except routes that I declare inside the jwt.js file.
- the
'/trial'
url, is not protected. The controller is inside thetrial.controller.js
file. When I hit the url in postman, both with theget
and thepost
method and without any auth (No Auth
), I get what I expect. - But, the same things do not happen when I hit
'/users/testdata'
. It's not protected, but if I hit it with theget
method and without any auth, it returnserror 500
with the message"Cannot read property 'sub' of undefined"
in postman. But, when I hit it with thepost
method, I get what I expect.
So, what's wrong with the get
method?
Please see the above link for complete code. Any help will mean a lot to me. Thank you!