You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
After a user logs in, I'm storing the tokens via AsyncStorage and trying to fetch the user's profile upon re-visiting the app.
This appears to be super simple in the Auth0 API docs but I'm getting back the message "Unauthorized" in my app:
asyncgetUserinfo(){console.log('getting user info in getUserInfo()');try{letresponse=awaitfetch('https://xxxxx.auth0.com/userinfo',{method: 'GET',headers: {Authorization: 'Bearer ${this.state.token.accessToken}',},});letresponseJson=awaitresponse.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});}}
What am I missing? I can't find many examples of using fetch with Auth0, is there a better method I should be using?
The text was updated successfully, but these errors were encountered:
@allpwrfulroot glad it work but probably you where confusing the apostrophe ' with the back-tick ` since it's the character used for String templates in ES6
Maybe in your case it's not applicable, but in the docs I found that one should call the 'getUserInfo' on the lock an simply pass the accessToken and the callback as args: https://github.com/auth0/lock
Like this:
lock.on("authenticated", function(authResult) {
lock.getUserInfo(authResult.accessToken, function(error, profile) {
if (error) {
// Handle error
return;
}
localStorage.setItem("idToken", authResult.idToken);
localStorage.setItem("profile", JSON.stringify(profile));
// Update DOM
});
});
But I suppose it depends on how you're using Auth0. If you're not using the Lock or you want to get the info without the lock, it doesn't apply here.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
After a user logs in, I'm storing the tokens via AsyncStorage and trying to fetch the user's profile upon re-visiting the app.
This appears to be super simple in the Auth0 API docs but I'm getting back the message "Unauthorized" in my app:
What am I missing? I can't find many examples of using fetch with Auth0, is there a better method I should be using?
The text was updated successfully, but these errors were encountered: