add some debug info
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using DiunaBI.UI.Shared.Services;
|
using DiunaBI.UI.Shared.Services;
|
||||||
|
using DiunaBI.UI.Shared.Handlers;
|
||||||
|
|
||||||
namespace DiunaBI.UI.Shared.Extensions;
|
namespace DiunaBI.UI.Shared.Extensions;
|
||||||
|
|
||||||
@@ -7,10 +8,23 @@ public static class ServiceCollectionExtensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddSharedServices(this IServiceCollection services, string apiBaseUrl)
|
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
|
// Ensure BaseAddress ends with / for proper relative URL resolution
|
||||||
var baseUri = apiBaseUrl.EndsWith('/') ? apiBaseUrl : apiBaseUrl + "/";
|
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
|
||||||
services.AddScoped<AuthService>();
|
services.AddScoped<AuthService>();
|
||||||
|
|||||||
28
src/Backend/DiunaBI.UI.Shared/Handlers/HttpLoggingHandler.cs
Normal file
28
src/Backend/DiunaBI.UI.Shared/Handlers/HttpLoggingHandler.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,7 +36,6 @@ public class AuthService
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"=== ValidateWithBackend: Sending Google credential for {email} ===");
|
Console.WriteLine($"=== ValidateWithBackend: Sending Google credential for {email} ===");
|
||||||
|
|
||||||
// Wyślij Google credential do backendu
|
|
||||||
var response = await _httpClient.PostAsJsonAsync("Auth/apiToken", googleCredential);
|
var response = await _httpClient.PostAsJsonAsync("Auth/apiToken", googleCredential);
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
@@ -53,11 +52,9 @@ public class AuthService
|
|||||||
AvatarUrl = avatarUrl
|
AvatarUrl = avatarUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
// Zapisz do localStorage
|
|
||||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "api_token", _apiToken);
|
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "api_token", _apiToken);
|
||||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "user_info", JsonSerializer.Serialize(_userInfo));
|
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "user_info", JsonSerializer.Serialize(_userInfo));
|
||||||
|
|
||||||
// Ustaw header dla przyszłych requestów
|
|
||||||
_httpClient.DefaultRequestHeaders.Authorization =
|
_httpClient.DefaultRequestHeaders.Authorization =
|
||||||
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);
|
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user