React axios 401 unauthorized

You are facing this because your req.user is empty that's why it goes to else statement and returns Unauthorized which you are returning.

Check your server console if it is printing anything console.log(res.locals.user);

Send your auth token with headers like this

headers : {
  'Content-Type' : 'application/json',
  'Accept' : 'application/json',
  'Authorization' : 'Bearer <token_here>'
}

Updated

Your request will always return 401 unauthorized.

https://github.com/manjurulhoque/nodejs-ecommerce-api/blob/master/routes/users.js#L105

Check my code. To get logged in user you have to use

passport.authenticate('jwt', { session: false })