add some debug info
All checks were successful
Build Docker Images / test (push) Successful in 1m14s
Build Docker Images / build-and-push (push) Successful in 1m37s

This commit is contained in:
2025-11-19 17:30:36 +01:00
parent c0a1945465
commit 66a9b975a5
3 changed files with 44 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using DiunaBI.UI.Shared.Services;
using DiunaBI.UI.Shared.Handlers;
namespace DiunaBI.UI.Shared.Extensions;
@@ -7,10 +8,23 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddSharedServices(this IServiceCollection services, string apiBaseUrl)
{
// HttpClient for API calls
// HttpClient for API calls with logging
// Ensure BaseAddress ends with / for proper relative URL resolution
var baseUri = apiBaseUrl.EndsWith('/') ? apiBaseUrl : apiBaseUrl + "/";
services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(baseUri) });
services.AddTransient<HttpLoggingHandler>();
services.AddHttpClient<AuthService>(client =>
{
client.BaseAddress = new Uri(baseUri);
})
.AddHttpMessageHandler<HttpLoggingHandler>();
services.AddHttpClient<LayerService>(client =>
{
client.BaseAddress = new Uri(baseUri);
})
.AddHttpMessageHandler<HttpLoggingHandler>();
// Services
services.AddScoped<AuthService>();

View File

@@ -0,0 +1,28 @@
namespace DiunaBI.UI.Shared.Handlers;
public class HttpLoggingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
Console.WriteLine($"🌐 HTTP Request: {request.Method} {request.RequestUri}");
Console.WriteLine($" BaseAddress: {request.RequestUri?.GetLeftPart(UriPartial.Authority)}");
Console.WriteLine($" Path: {request.RequestUri?.PathAndQuery}");
if (request.Headers.Authorization != null)
{
Console.WriteLine($" Auth: {request.Headers.Authorization.Scheme} {request.Headers.Authorization.Parameter?[..Math.Min(20, request.Headers.Authorization.Parameter?.Length ?? 0)]}...");
}
else
{
Console.WriteLine($" Auth: None");
}
var response = await base.SendAsync(request, cancellationToken);
Console.WriteLine($" Response: {(int)response.StatusCode} {response.StatusCode}");
return response;
}
}

View File

@@ -36,7 +36,6 @@ public class AuthService
{
Console.WriteLine($"=== ValidateWithBackend: Sending Google credential for {email} ===");
// Wyślij Google credential do backendu
var response = await _httpClient.PostAsJsonAsync("Auth/apiToken", googleCredential);
if (response.IsSuccessStatusCode)
@@ -53,11 +52,9 @@ public class AuthService
AvatarUrl = avatarUrl
};
// Zapisz do localStorage
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "api_token", _apiToken);
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "user_info", JsonSerializer.Serialize(_userInfo));
// Ustaw header dla przyszłych requestów
_httpClient.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);