-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix Blazor template bug where a logged in user could appear to be unauthenticated #51497
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
Hi @halter73. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document. |
PersistentComponentState is only available during the first render by design. It's available only when a given runtime starts. |
Hi @halter73. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Hi @halter73. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
9c1f488
to
9be2b4a
Compare
9be2b4a
to
e8c86be
Compare
Description
A customer reported that after enhanced navigation from a WebAssembly-rendered component that does not require authentication state to another WebAssembly-rendered component that does, the client will lose its authentication state. This leads to issues where the server knows the client is authenticated meaning the client can navigate to components that require authentication, but the client thinks the user is unauthenticated for the purposes of rendering something like:
This was caused by the
PersistentAuthenticationStateProvider
on the client attempting to read theUserInfo
fromPersistentComponentState
after enhanced navigation. At this point the state from the original page load (/counter
in the examples below) is cleared, and the state that was persisted during the enhanced navigation to/auth
is simply ignored and never read by anyone despite calling theRegisterOnPersisting
callback and rendering the state for each enhanced navigation. ThePersistentComponentState
behavior is by design according to @javiercn, and we can make auth work reliably with the currentPersistentComponentState
behavior by greedily reading theUserInfo
during initial render before any enhanced navigation which is what this PR does.Fixes #51368
Customer Impact
This was thankfully reported by a customer trying out the new Identity Blazor components in RC2. It's possible to get into this state with just the template code if a browser session starts in (or reload on) the template's
/counter
page and then does enhanced navigation to a component that uses an<AuthorizeView>
like the template's/auth
page. Without this fix, the user is forced to refresh the/auth
page or any other page with<AuthorizeView>
before they can see any rendered content that requires authorization.auth-persistent-state-bug-refresh.mp4
Notice how the second time I navigate to the "Auth Required" page after refreshing on the "Counter" page, you see "You are authenticated" followed by "You are not authorized" even though any authenticated user should be authorized to see that page. After the fix, you always see "You are authenticated" followed by "You are authorized" and "Hello {email}!" as expected.
auth-persistent-state-fix.mp4
Regression?
Risk
This is a small change to a single Blazor Identity template component added in RC 2 which slightly simplifies the logic.
Verification
Packaging changes reviewed?