UnauthorizedError: jwt malformed error when authenticating

If you haven’t done so already you should perform these steps:

  1. capture the token you receive; for example, using a console.log statement given this is in development.
  2. review the captured token; does it look like a JWT?
  3. if its a JWT and you can parse it at jwt.io then update the API to log the received token before trying to validate it; does the received token match the one you expect?

In conclusion, try to take steps that allow you to gather a bit more of information.