Functionality of useAuth0 hook in react

Hi Team,

I am using auth0-spa-js in my React code.

const { user, getAccessTokenSilently } = useAuth0();

I am using getAccessTokenSilently method of useAuth0 hook to get the token for different users by creating some rules in Auth0. Once after triggering the method, i am getting the token which I am expecting.

But when I use the user variable provided by useAuth0 hook immediately after triggering the token method call, it still has the old user value which I expect it be updated with new user details. At times, user variable is getting updated with new user details, but I am not getting how exactly it works in the background.

const { user } = useAuth0();

Can anyone please explain how & when the user variable provided by useAuth0 hook gets it’s value assigned.?

Thanks in advance,

Hi @harigovind2295,

The user is the decoded payload of the ID token that your app is issued after a user logs in or after silent authentication takes place.

To troubleshoot this, you can take a look at the network tab and find the request to https://YOUR_DOMAIN/oauth/token. The response will contain an Access Token and an ID Token. You can paste the ID Token to verify that the user matches the ID Token claims.

Are you adding ID Token claims using rules or actions? If silent authentication, it’s possible that the rule or action is not able to add the custom claim if the data permanently saved on the user (e.g. stored in app metadata).

1 Like

Hi @stephanie.chamblee ,

Thanks for the reply. It helped me in implementing my requirement. Sorry for the delayed response.



No worries! Glad it’s working now!