I am trying to save userId and token in securestore. On the next screen I can get token from securestore, but I can't see userid
const doUserLogIn = async() => {
try {
const response = await fetch('http://someurl-dev.de/api/login/?email='+email+'&password='+password, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
const json = await response.json();
SecureStore.setItemAsync('userid', json.userId);
SecureStore.setItemAsync('token', json.token);
} catch (e) {
alert('Error1:'+e);
} finally {
try{
navigation.navigate('Schichten');
} catch(e) {alert('Error2:'+e); }
}
}
And here's the json returned by api call
{"userId":9,"token":"957a230f3eb6e63c47f1d7a0805fe31df6d2ced7","vorname":"Ankit","nachname":"Vij"}
You are not awaiting the async functions setItemAsync. You should try the following:
await SecureStore.setItemAsync('userid', json.userId);
await SecureStore.setItemAsync('token', json.token);
Additionally, you can try to log the value of the json variable to make sure that it does contain the userId and token properties.