我已经创建了一个阵营本地应用程序,使用Auth0认证(与下面的身份验证代码示例):呼叫一个异步函数来验证过程中存储的accessToken阵营本地
_onLogin() {
auth0
.webAuth
.authorize({scope: 'openid email', audience: 'https://' + credentials.domain + '/userinfo'})
.then(credentials => Alert.alert(
'Login Success',
'AccessToken: ' + credentials.accessToken,
[
{text: 'OK', onPress:() => console.log('OK Pressed')},
],
{ cancelable: false },
Actions.home()
))
.catch(error => console.log(error));
}
,我有这个简单的功能用于将一些值存储到AsyncStorage中(在这种情况下,我希望将credentials.accessToken
正确给出的accessToken存储在上面的函数中)。
async _storeSomeValues(item, selectedValue) {
try {
await AsyncStorage.setItem(item, selectedValue);
} catch (error) {
console.log('AsyncStorage error: ' + error.message);
}
}
我查了很多帖子,尝试了很多方法来使用此功能为.then(...)
的声明,但它总是告诉我这个错误:
ReferenceError: _storeSomeValues is not defined
为什么没有定义我的功能这里?
这是我第一个反应本机应用程序,我从来没有编码与反应之前。
你在哪里调用'_storeSomeValues'? – kytwb
我真的不知道如何将我的'_storeSomeValues'函数调用到我的 .then(...)语句中。 我试过很多方法来调用它,但它总是显示我的错误。 –
我发现问题,我只需要声明_onLogin函数就像一个箭头函数。然后,我可以调用'_storeSomeValues'就像'this._storeSomeValues(params ....)' –