Skip to content

Commit 6c2de75

Browse files
Copilotilonatommy
andcommitted
Update DeserializedAuthenticationStateProvider to use SupplyParameterFromPersistentComponentState
Co-authored-by: ilonatommy <[email protected]>
1 parent 5fd53dd commit 6c2de75

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/DeserializedAuthenticationStateProvider.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ internal sealed class DeserializedAuthenticationStateProvider : AuthenticationSt
1717
private static readonly Task<AuthenticationState> _defaultUnauthenticatedTask =
1818
Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
1919

20-
private readonly Task<AuthenticationState> _authenticationStateTask = _defaultUnauthenticatedTask;
20+
private Task<AuthenticationState> _authenticationStateTask = _defaultUnauthenticatedTask;
21+
22+
[SupplyParameterFromPersistentComponentState]
23+
private AuthenticationStateData? AuthStateData { get; set; }
2124

2225
[UnconditionalSuppressMessage(
2326
"Trimming",
@@ -28,12 +31,18 @@ internal sealed class DeserializedAuthenticationStateProvider : AuthenticationSt
2831
[DynamicDependency(JsonSerialized, typeof(ClaimData))]
2932
public DeserializedAuthenticationStateProvider(PersistentComponentState state, IOptions<AuthenticationStateDeserializationOptions> options)
3033
{
31-
if (!state.TryTakeFromJson<AuthenticationStateData?>(PersistenceKey, out var authenticationStateData) || authenticationStateData is null)
34+
// For backwards compatibility, try to read from the direct state first
35+
if (AuthStateData is null &&
36+
state.TryTakeFromJson<AuthenticationStateData?>(PersistenceKey, out var authenticationStateData) &&
37+
authenticationStateData is not null)
3238
{
33-
return;
39+
AuthStateData = authenticationStateData;
3440
}
3541

36-
_authenticationStateTask = options.Value.DeserializationCallback(authenticationStateData);
42+
if (AuthStateData is not null)
43+
{
44+
_authenticationStateTask = options.Value.DeserializationCallback(AuthStateData);
45+
}
3746
}
3847

3948
public override Task<AuthenticationState> GetAuthenticationStateAsync() => _authenticationStateTask;

0 commit comments

Comments
 (0)