fix: add authorization header to AdminDashboardClient
TaxBaik CI/CD / build-and-deploy (push) Successful in 50s
TaxBaik CI/CD / build-and-deploy (push) Successful in 50s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Net.Http;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using TaxBaik.Application.Services;
|
using TaxBaik.Application.Services;
|
||||||
using TaxBaik.Domain.Entities;
|
using TaxBaik.Domain.Entities;
|
||||||
@@ -21,17 +22,28 @@ public class AdminDashboardClient : IAdminDashboardClient
|
|||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
private readonly HttpClient _http;
|
||||||
private readonly ILogger<AdminDashboardClient> _logger;
|
private readonly ILogger<AdminDashboardClient> _logger;
|
||||||
|
private readonly ITokenStore _tokenStore;
|
||||||
|
|
||||||
public AdminDashboardClient(HttpClient http, ILogger<AdminDashboardClient> logger)
|
public AdminDashboardClient(HttpClient http, ILogger<AdminDashboardClient> logger, ITokenStore tokenStore)
|
||||||
{
|
{
|
||||||
_http = http;
|
_http = http;
|
||||||
_logger = logger;
|
_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<AdminDashboardSummary> GetSummaryAsync(CancellationToken ct = default)
|
public async Task<AdminDashboardSummary> GetSummaryAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureAuthHeader();
|
||||||
var result = await _http.GetFromJsonAsync<AdminDashboardSummary>(
|
var result = await _http.GetFromJsonAsync<AdminDashboardSummary>(
|
||||||
"admin-dashboard/summary", cancellationToken: ct);
|
"admin-dashboard/summary", cancellationToken: ct);
|
||||||
return result ?? new(0, 0, 0, 0, []);
|
return result ?? new(0, 0, 0, 0, []);
|
||||||
@@ -47,6 +59,7 @@ public class AdminDashboardClient : IAdminDashboardClient
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureAuthHeader();
|
||||||
var result = await _http.GetFromJsonAsync<ApiResponse<TaxFiling>>(
|
var result = await _http.GetFromJsonAsync<ApiResponse<TaxFiling>>(
|
||||||
$"admin-dashboard/upcoming-filings?days={days}", cancellationToken: ct);
|
$"admin-dashboard/upcoming-filings?days={days}", cancellationToken: ct);
|
||||||
return result?.Data ?? [];
|
return result?.Data ?? [];
|
||||||
@@ -62,6 +75,7 @@ public class AdminDashboardClient : IAdminDashboardClient
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureAuthHeader();
|
||||||
var result = await _http.GetFromJsonAsync<ApiResponse<Inquiry>>(
|
var result = await _http.GetFromJsonAsync<ApiResponse<Inquiry>>(
|
||||||
$"admin-dashboard/recent-inquiries?limit={limit}", cancellationToken: ct);
|
$"admin-dashboard/recent-inquiries?limit={limit}", cancellationToken: ct);
|
||||||
return result?.Data ?? [];
|
return result?.Data ?? [];
|
||||||
@@ -77,6 +91,7 @@ public class AdminDashboardClient : IAdminDashboardClient
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureAuthHeader();
|
||||||
var url = "admin-dashboard/monthly-stats";
|
var url = "admin-dashboard/monthly-stats";
|
||||||
if (!string.IsNullOrEmpty(month))
|
if (!string.IsNullOrEmpty(month))
|
||||||
url += $"?month={month}";
|
url += $"?month={month}";
|
||||||
|
|||||||
Reference in New Issue
Block a user