Always getting 401 (Unauthorized) error with axios. post or get

You get this error about the invalid token because your request also sends an authorization header with the token.

If you open Developer tools, go to the network tab, repeat the login/register request, you will notice that in Requests Headers section of this request, there is an Authorization: Bearer {token} header. To solve this just delete the cookies/local storage from your localhost. Axios by default adds all the cookies to your requests, so