user is not updated after getAccessTokenSilently({ignoreCache: true})
Describe the problem
When you refresh the access token and ignore the cache, there are potentially new claims on the user object. However, the user object is stale and there is no way to update it. https://github.com/auth0/auth0-spa-js/issues/274 explains the issue and has a solution: you can call getUser() after you refresh the token. But we have no way to call getUser().
Right now, to get around this, you must hard-refresh the page.
Exposing the getUser function from the auth0-spa-js client would solve this.
What was the expected behavior?
The user object should have all the claims of the new token.
Reproduction
Create a rule in auth0 that sets a property e.g.
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if (user.app_metadata.mything) {
context.idToken['https://myapp.com/mything'] = true;
context.accessToken['https://myapp.com/mything'] = true;
}
callback(null, user, context);
}
Periodically call getAccessTokenSilently({ignoreCache: true}) without refreshing/reloading the page. Observe the user from useAuth0(). It will not have the claim. Refreshing the page will populate the user with the claim.
Environment
Version: 1.0.0 Browsers: Chrome
Hi @type - thanks for raising this
We're aware of this limitation and have an item in the backlog to address it and a branch that I'll be raising a PR for in a couple of weeks (I'm away next week)
In the meantime getIdTokenClaims should provide you with the updated user claims.
Great to hear that @adamjmcgrath ! I had started on a solution with getIdTokenClaims so I'll continue down that road for now.
Thanks, @adamjmcgrath! It's much more elegant to update the user object. I'm excited for this PR to go through.
@adamjmcgrath Any updates on when these changes will be implemented?
@alex-zwingli - it's on our backlog, I can't give you a specific date yet, but I'll update this post when I've raised a PR