I got an api request using axios coming from my backend server. I want to save the bearer token to the device storage or local storage. But when i do console.log for the bearer token, it seems not working because what i get is something like a promise.
Here is my method
import {AsyncStorage, Alert} from 'react-native';
export default function login(email,password,setLoading){
console.log('Loading...')
setLoading(true)
axios.post('http://52.74.70.6/api/auth/login',{
email: email,
password: password
},{
headers:{
Accept: 'application/json',
'Content-Type': 'application/json',
}
})
.then((res)=>{
setLoading(false)
AsyncStorage.setItem('bearer_token', res.data.bearer_token);
console.log(AsyncStorage.getItem('bearer_token'))
console.log('Loading Finished')
}).catch((err)=>{
setLoading(false)
console.log(err)
AlertErr()
})
}
What I got is
Loading...
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
Loading Finished