Skip to content

Commit 75fc6a1

Browse files
Copilotilonatommy
andcommitted
Refactor AuthenticationStateSerializer to use declarative persistent component state
Co-authored-by: ilonatommy <[email protected]>
1 parent 37de7d3 commit 75fc6a1

File tree

9 files changed

+18
-164
lines changed

9 files changed

+18
-164
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/WebAssembly/Server/src/AuthenticationStateSerializer.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ internal sealed class AuthenticationStateSerializer : IHostEnvironmentAuthentica
1717
private readonly PersistingComponentStateSubscription _subscription;
1818

1919
private Task<AuthenticationState>? _authenticationStateTask;
20+
private AuthenticationStateData? _authenticationStateData;
21+
22+
[PersistentComponentStateStore]
23+
public AuthenticationStateData? AuthStateData
24+
{
25+
get => _authenticationStateData;
26+
set => _authenticationStateData = value;
27+
}
2028

2129
public AuthenticationStateSerializer(PersistentComponentState persistentComponentState, IOptions<AuthenticationStateSerializationOptions> options)
2230
{
@@ -32,11 +40,7 @@ private async Task OnPersistingAsync()
3240
throw new InvalidOperationException($"{nameof(SetAuthenticationState)} must be called before the {nameof(PersistentComponentState)}.{nameof(PersistentComponentState.RegisterOnPersisting)} callback.");
3341
}
3442

35-
var authenticationStateData = await _serializeCallback(await _authenticationStateTask);
36-
if (authenticationStateData is not null)
37-
{
38-
_state.PersistAsJson(PersistenceKey, authenticationStateData);
39-
}
43+
AuthStateData = await _serializeCallback(await _authenticationStateTask);
4044
}
4145

4246
/// <inheritdoc />

src/Components/WebAssembly/Server/src/WebAssemblyRazorComponentsBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Components;
55
using Microsoft.AspNetCore.Components.Authorization;
66
using Microsoft.AspNetCore.Components.Endpoints.Infrastructure;
7+
using Microsoft.AspNetCore.Components.Infrastructure;
78
using Microsoft.AspNetCore.Components.WebAssembly.Server;
89
using Microsoft.AspNetCore.Components.WebAssembly.Services;
910
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -41,6 +42,7 @@ public static IRazorComponentsBuilder AddInteractiveWebAssemblyComponents(this I
4142
public static IRazorComponentsBuilder AddAuthenticationStateSerialization(this IRazorComponentsBuilder builder, Action<AuthenticationStateSerializationOptions>? configure = null)
4243
{
4344
builder.Services.TryAddEnumerable(ServiceDescriptor.Scoped<IHostEnvironmentAuthenticationStateProvider, AuthenticationStateSerializer>());
45+
RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<AuthenticationStateSerializer>(builder.Services, RenderMode.InteractiveWebAssembly);
4446
if (configure is not null)
4547
{
4648
builder.Services.Configure(configure);

src/JSInterop/Microsoft.JSInterop.JS/src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"rimraf": "^5.0.5",
4545
"typescript": "^5.3.3"
4646
}
47-
}
47+
}

src/JSInterop/Microsoft.JSInterop.JS/src/package.json.bak

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/SignalR/clients/ts/signalr-protocol-msgpack/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/signalr-protocol-msgpack",
3-
"version": "10.0.0-dev",
3+
"version": "5.0.0-dev",
44
"description": "MsgPack Protocol support for ASP.NET Core SignalR",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",
@@ -41,11 +41,11 @@
4141
"src/**/*"
4242
],
4343
"dependencies": {
44-
"@microsoft/signalr": ">=10.0.0-dev",
44+
"@microsoft/signalr": "*",
4545
"@msgpack/msgpack": "^2.7.0"
4646
},
4747
"overrides": {
4848
"ws": ">=7.4.6",
4949
"tough-cookie": ">=4.1.3"
5050
}
51-
}
51+
}

src/SignalR/clients/ts/signalr-protocol-msgpack/package.json.bak

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/SignalR/clients/ts/signalr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/signalr",
3-
"version": "10.0.0-dev",
3+
"version": "5.0.0-dev",
44
"description": "ASP.NET Core SignalR Client",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

src/SignalR/clients/ts/signalr/package.json.bak

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)