diff --git a/NEW/src/JdeScoping.Client/Program.cs b/NEW/src/JdeScoping.Client/Program.cs index bac90cd..41b4268 100644 --- a/NEW/src/JdeScoping.Client/Program.cs +++ b/NEW/src/JdeScoping.Client/Program.cs @@ -1,6 +1,9 @@ using JdeScoping.Client; using JdeScoping.Client.Auth; +using JdeScoping.Client.Http; using JdeScoping.Client.Services; +using JdeScoping.Core.ApiContracts; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -10,11 +13,20 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -// Configure HttpClient with base address +// Configure HttpClient with AuthRedirectHandler for global 401 handling // In Blazor WebAssembly, the browser automatically handles cookies for same-origin requests -builder.Services.AddScoped(sp => new HttpClient +builder.Services.AddScoped(); +builder.Services.AddScoped(sp => { - BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) + var navigationManager = sp.GetRequiredService(); + var handler = new AuthRedirectHandler(navigationManager) + { + InnerHandler = new HttpClientHandler() + }; + return new HttpClient(handler) + { + BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) + }; }); // Radzen services @@ -40,4 +52,10 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +// New typed API clients (shared contracts) +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + await builder.Build().RunAsync();