axios react with bearar tokan code example
Example 1: autherization token in axios
const api = 'your api';
const token = JSON.parse(sessionStorage.getItem('data'));
const token = user.data.id;
axios.get(api , { headers: {"Authorization" : `Bearer ${token}`} })
.then(res => {
console.log(res.data);
.catch((error) => {
console.log(error)
});
Example 2: how to authenticate token in react using axios
const api = `your api here`
axios.get(api, { headers: {"Authorization" : `Bearer ${token}`} })
.then(res => {
console.log(res.data);
this.setState({
items: res.data,
isLoaded : true,
redirectToReferrer: false
})