Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-1938] Update the user/isAuthenticated state after getting a token #146

Merged
merged 2 commits into from
Oct 28, 2020

Conversation

adamjmcgrath
Copy link
Contributor

Description

Everytime we call getAccessToken*, update the user from the spa client - since it may have been updated.

With the caveat that, if you're relying on the user as a dependant key of some memoized operation, the reference to the user might change when the user properties haven't. eg

// DON'T
useEffect(() => {
  (async () => {
    setProfile(await fetch(`/profile/{user.sub}`));
  })()
}, [user]) // <= ref might change

// DO
useEffect(() => {
  (async () => {
    setProfile(await fetch(`/profile/{user.sub}`));
  })()
}, [user.sub]) // <= primitive won't change

References

Fixes #109

Testing

Given I login to the auth0-react playground
And I update the user's claims
When I click getAccessTokenSilently
Then the user's claims should be updated

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@adamjmcgrath adamjmcgrath added the review:medium Medium review label Oct 28, 2020
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner October 28, 2020 12:11
@adamjmcgrath adamjmcgrath changed the title Update the user/isAuthenticated state after getting a token [SDK-1938] Update the user/isAuthenticated state after getting a token Oct 28, 2020
@adamjmcgrath adamjmcgrath mentioned this pull request Oct 28, 2020
4 tasks
const user = await client.getUser();
dispatch({ type: 'GET_TOKEN_COMPLETE', user });
return token;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we went for a shared wrappedGetToken utils to a duplicated yet identical (besides the actual token call) code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signatures are different too (the old wrappedGetToken didn't account for PopupConfigOptions ) that felt like a good enough reason to split them into 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow so that means the second argument in case of popup was never passed along? That is a nice catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - @ygist caught that one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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