0
我正在使用Auth0的react-native-lock小部件进行用户验证,并且在成功登录后,我将存储令牌与AsyncStorage。在React Native中获取来自Auth0应用程序的userinfo
如果用户回到应用程序,我希望能够跳过登录并简单地从Auth0获取当前用户信息。这似乎从该Auth0 API docs非常容易的,但我在我的应用程序取回消息“未经授权”:
async getUserinfo() {
console.log('getting user info in getUserInfo()');
try {
let response = await fetch('https://xxxxx.auth0.com/userinfo', {
method: 'GET',
headers: {
Authorization: 'Bearer ${this.state.token.accessToken}',
},
});
let responseJson = await response.json();
if(responseJson !== null) {
console.log('Got user info: ' + responseJson.email);
this.setState({ component: Temp, isLoading: false, profile: responseJson});
}
} catch (error) {
console.log('Error in retrieving userinfo from Auth0: ' + error.message);
this.setState({ component: Login, isLoading: false});
}
}
我缺少什么?我找不到很多使用Auth0提取的例子,有没有更好的方法可以使用?