fix(web): register HeimdallAuthStateProvider concrete type in DI

The service was registered only as AuthenticationStateProvider (base class),
but Login.razor, Register.razor, and MainLayout.razor inject the concrete
@inject HeimdallAuthStateProvider. Blazor's DI could not resolve it,
causing InvalidOperationException on page render.

Fix: register the concrete type first, then make the base class
registration resolve to the same instance via GetRequiredService.
This commit is contained in:
Arnaud Dartois committed 2026-07-18 21:08:08 +00:00
1 parent 39f08e39ed
commit 8c6b2610a0
1 file changed
+5 -1
+5 -1
View File
@@ -47,7 +47,11 @@ builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
// Blazor auth state provider (reads JWT from ProtectedLocalStorage)
builder.Services.AddScoped<AuthenticationStateProvider, HeimdallAuthStateProvider>();
// Register the concrete type so @inject HeimdallAuthStateProvider works in pages,
// then make the base AuthenticationStateProvider resolve to the same instance.
builder.Services.AddScoped<HeimdallAuthStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(
sp => sp.GetRequiredService<HeimdallAuthStateProvider>());
// ── MudBlazor ─────────────────────────────────────────────────────
builder.Services.AddMudServices(config =>