auth0-react icon indicating copy to clipboard operation
auth0-react copied to clipboard

user is not updated after getAccessTokenSilently({ignoreCache: true})

Open type opened this issue 6 years ago • 5 comments

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

type avatar Sep 04 '20 02:09 type

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.

adamjmcgrath avatar Sep 04 '20 10:09 adamjmcgrath

Great to hear that @adamjmcgrath ! I had started on a solution with getIdTokenClaims so I'll continue down that road for now.

type avatar Sep 04 '20 19:09 type

Thanks, @adamjmcgrath! It's much more elegant to update the user object. I'm excited for this PR to go through.

alex-zwingli avatar Sep 09 '20 05:09 alex-zwingli

@adamjmcgrath Any updates on when these changes will be implemented?

alex-zwingli avatar Sep 29 '20 22:09 alex-zwingli

@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

adamjmcgrath avatar Oct 02 '20 11:10 adamjmcgrath