i am trying to store the response.data.token into sessionstorage or localstorage how can i do it from inside the axios then
const getdata = async () => {
var date2 = moment(mydate2).format('DD/MM/YYYY');
var date = moment(mydate).format('DD/MM/YYYY');
var todaydate = moment(new Date()).format('DD/MM/YYYY');
if (date == todaydate && date2 != todaydate) {
var Data56 = {
name: name,
email: email,
babyname: babyname,
phone: nuber,
period: date2,
// baby_date: date,
};
} else {
var Data56 = {
name: name,
email: email,
babyname: babyname,
phone: nuber,
// period: date2,
baby_date: date,
};
}
axios({
method: 'POST',
url: 'http://127.0.0.1:8000/api/register',
data: Data56,
})
.then(async response => {
await AsyncStorage.setItem('token', `${response.data.token}`);
alert('sucess ');
})
.catch(error => {
alert(JSON.stringify(error.response.data));
});
};
i am trying to store the response.data.token into sessionstorage or localstorage how can i do it from inside the axios then
2
Answers
==> Update Your code like this:-
Setting data to Asyncstorage works asynchronous so you need set with await like this: