How to pass Header JWT Token with Axios & React?

前端 未结 4 863
你的背包
你的背包 2021-01-31 11:57

I make web application with React, Express, MongoDB.

And, I want to pass jwt token with header.

But, I pass it, get 401 error (Unauthorized).

In login ac

4条回答
  •  一整个雨季
    2021-01-31 12:26

    Include your token as authorization key as below.

    axios.post(url,data, {
        headers: {
            'authorization': your_token,
            'Accept' : 'application/json',
            'Content-Type': 'application/json'
        }
    })
    .then(response => {
        // return  response;
    })
    .catch((error) => {
        //return  error;
    });
    

提交回复
热议问题