using Microsoft.JSInterop; using System.Net.Http.Headers; namespace OnProfNext.Client.Services { public class AuthorizationMessageHandler : DelegatingHandler { private readonly IJSRuntime _js; public AuthorizationMessageHandler(IJSRuntime js) => _js = js; protected override async Task SendAsync(HttpRequestMessage request, CancellationToken ct) { var token = await _js.InvokeAsync("localStorage.getItem", "authToken"); if (!string.IsNullOrWhiteSpace(token)) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); return await base.SendAsync(request, ct); } } }