Hi guys, I’m using the react 02-user-profile sample here: https://github.com/auth0-samples/auth0-react-samples/tree/master/02-User-Profile
I’m just wondering if there’s a way to display the user info right after they login and the get called back to the react application. I can see in the sample code I’m able to get the userinfo but only if I change to a different route after the callback.
When I tried modifying the code like below in App.js and Auth.js so that the auth prop has the userProfile after handleAuthentication(), the userProfile does not get rendered to screen.
{
isAuthenticated() && (
<div className="container">
<div className="profile-area">
<h1>{userProfile.name}</h1>
<Panel header="Profile">
<img src={userProfile.picture} alt="profile" />
<div>
<ControlLabel><Glyphicon glyph="user" /> Nickname</ControlLabel>
<h3>{userProfile.nickname}</h3>
</div>
<pre>{JSON.stringify(userProfile, null, 2)}</pre>
</Panel>
</div>
</div>
)
}
This is my Auth.js authentication:
userProfile = {};
handleAuthentication() {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.auth0.client.userInfo(authResult.accessToken, (err, profile) => {
if (profile) {
this.userProfile = profile;
}
});
this.setSession(authResult);
history.replace('/home');
} else if (err) {
history.replace('/home');
console.log(err);
alert(`Error: ${err.error}. Check the console for further details.`);
}
});
}