I am trying to make an axios get request but am receiving 401 everytime am trying to fetch. However am already logged in as I have previously received my user login response My project has been built with react native init and is running on browser using react-native-web. The same api when I check the response on mobile and postman it is giving the correct response however on browser it is throwing 401 below is my axios code
useEffect(() => {
let url = `${ROOT}/children/${id}/vaccinations`;
axios
.get(url)
.then(function (res) {
console.log("Hello", res);
setData(res.data.content);
})
.catch(function (err) {
console.log(err);
});
}, []);
The response of 3 apis that are being called
The error that am receiving [![enter image description here][2]][2]
could anyone please tell me where am going wrong? any help would be appreciated. [2]: https://i.stack.imgur.com/17Qyf.png
401 code error means you are not authorized, you would need to send your user token that you receive from the backend as a header when sending your specified request, something like that:
You can read more about sending tokens in headers via this link: https://flaviocopes.com/axios-send-authorization-header/
I hope this helps in solving your issue.