-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix useIsAuthenticated
hook briefly returning false even though the user is authenticated
#7057
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
Conversation
@microsoft-github-policy-service agree company="Giant Eagle" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I imagine there's other places we can make similar changes.
Co-authored-by: Thomas Norling <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, small nit
change/@azure-msal-react-5355b5e3-0c1c-4e23-ae9d-a6d96ef4285d.json
Outdated
Show resolved
Hide resolved
thanks @hatched-kade! @tnorling @jo-arroyo could we (you) do a release of msal-react please? we are also impacted by #6918 and would rather not install from dev branch. thanks |
Addresses #6918
The current
useIsAuthenticated
has an unnecessaryuseEffect
, which causes it to briefly returnfalse
in some cases even when an account is present. See https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state and https://react.dev/learn/you-might-not-need-an-effect#caching-expensive-calculationsThis PR switches to use the
useMemo
recommendationI added a unit test that passes now, but fails with the old implementation:
I also had to tweak some act / await / async code in other tests, presumably because now it takes fewer renders for the hook to start returning the correct value. Without the tweaks a couple tests were failing, and others printed warning about updating state outside of an
act(...)
.