From e3a0ea03f08e91c5f349972666c746623103b04a Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sun, 28 Jun 2026 15:59:53 +0900 Subject: [PATCH] fix: add authorization header to AdminDashboardClient Apply same EnsureAuthHeader pattern for consistency across all API clients. Dashboard summary numbers now load correctly with proper JWT authentication in Blazor Server environment. Co-Authored-By: Claude Haiku 4.5 --- TaxBaik.Web/Services/AdminDashboardClient.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/TaxBaik.Web/Services/AdminDashboardClient.cs b/TaxBaik.Web/Services/AdminDashboardClient.cs index 5ab68b3..e264904 100644 --- a/TaxBaik.Web/Services/AdminDashboardClient.cs +++ b/TaxBaik.Web/Services/AdminDashboardClient.cs @@ -1,3 +1,4 @@ +using System.Net.Http; using System.Net.Http.Json; using TaxBaik.Application.Services; using TaxBaik.Domain.Entities; @@ -21,17 +22,28 @@ public class AdminDashboardClient : IAdminDashboardClient { private readonly HttpClient _http; private readonly ILogger _logger; + private readonly ITokenStore _tokenStore; - public AdminDashboardClient(HttpClient http, ILogger logger) + public AdminDashboardClient(HttpClient http, ILogger logger, ITokenStore tokenStore) { _http = http; _logger = logger; + _tokenStore = tokenStore; + } + + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(_tokenStore.AccessToken) && !_http.DefaultRequestHeaders.Contains("Authorization")) + { + _http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken); + } } public async Task GetSummaryAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); var result = await _http.GetFromJsonAsync( "admin-dashboard/summary", cancellationToken: ct); return result ?? new(0, 0, 0, 0, []); @@ -47,6 +59,7 @@ public class AdminDashboardClient : IAdminDashboardClient { try { + EnsureAuthHeader(); var result = await _http.GetFromJsonAsync>( $"admin-dashboard/upcoming-filings?days={days}", cancellationToken: ct); return result?.Data ?? []; @@ -62,6 +75,7 @@ public class AdminDashboardClient : IAdminDashboardClient { try { + EnsureAuthHeader(); var result = await _http.GetFromJsonAsync>( $"admin-dashboard/recent-inquiries?limit={limit}", cancellationToken: ct); return result?.Data ?? []; @@ -77,6 +91,7 @@ public class AdminDashboardClient : IAdminDashboardClient { try { + EnsureAuthHeader(); var url = "admin-dashboard/monthly-stats"; if (!string.IsNullOrEmpty(month)) url += $"?month={month}";