Howdy folks, it’s time for my first ask on here. Relatively new React dev here, and am very keen on Auth0 for my auth component. I followed Sam Julien’s excellent guide on implementation and have got it working, for my SPA which I’ve deployed to Netlify. I am NOT able to parse anything from the user object but user.nickname, and I need one or two user_metadata for some functions in the app.
For now I just need a single metadata I’ve put into a user profile:
{
"chartsite": "lt5"
}
I’ve understood that these metadata can be included in the id token without needing a management token by writing a rule which indicates that. So here’s the rule I’ve put into my Auth0 app:
Here’s a component snippet which is returning user.nickname but not user.chartsite on login (note, I am working in localhost:8000 and using development keys, apparently still, but that hasn’t hindered deploying the app to a live development site. Nonetheless I am getting warnings about that.
const Home = ({ user }) => {
console.log(user.chartsite)
return (
<Wrapper2>
<div class="generic">
<p>Hi, {user.nickname ? user.nickname : 'friend'}!</p>
<p>Your site name is {user.chartsite ? user.chartsite : 'unknown'} </p>
</div>
</Wrapper2>
)
}
First, the getProfile() method calls the Authentication API get user info endpoint, which returns the user profile information from the access token obtained from the /oauth/token endpoint. The user_metadata attribute is not one of the attributes returned in the response. Therefore, you’ll need to use the Rule to append custom claims to the tokens.
In this case, you’ll need to update your Rule with something like the following:
Hi @rueben.tiow ,
Thanks a lot for that suggestion.
I changed the rule, and updated my call from
user = authResult.idTokenPayload
to:
user = authResult.authTokenPayload
Not so simple. I am using the exact code that is published by Auth0 in this thread: