【发布时间】:2021-12-08 04:30:59
【问题描述】:
我正在尝试将用户 ID 和令牌保存在安全存储中。在下一个屏幕上,我可以从 Securestore 获取令牌,但我看不到用户 ID
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); }
}
}
这是api调用返回的json
{"userId":9,"token":"957a230f3eb6e63c47f1d7a0805fe31df6d2ced7","vorname":"Ankit","nachname":"Vij"}
【问题讨论】:
标签: javascript android reactjs react-native frontend