I am developing a react application and I have a Authorize.js file which contacts my backend and checks if the user is authorized or not.
AUTHORIZE.JS
import axios from 'axios';
const Authorize = async () => {
const data = axios
.get('https://[ENDPOINT]/user/info', {
headers: {
'x-jwt-token': localStorage.getItem('x-jwt-token'),
'x-token': localStorage.getItem('x-token'),
},
})
.then((res) => res.data.data)
.catch((err) => {
localStorage.removeItem('x-token');
localStorage.removeItem('x-jwt-token');
console.log(err.response);
});
return await data;
};
export default Authorize;
Even though I am using .catch at the end I am still getting an error in the console.
How do I remove that xhr.js GET 401 error? I think the .catch() is also working because it is printing the err.response
Any help would be highly appreciated!