SignalR FIX
All checks were successful
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m26s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m24s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m41s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m38s

This commit is contained in:
2025-12-06 00:36:22 +01:00
parent eb570679ba
commit 08abd96751
3 changed files with 62 additions and 8 deletions

View File

@@ -15,16 +15,18 @@ public class AuthService
{
private readonly HttpClient _httpClient;
private readonly IJSRuntime _jsRuntime;
private readonly TokenProvider _tokenProvider;
private bool? _isAuthenticated;
private UserInfo? _userInfo = null;
private string? _apiToken;
public event Action<bool>? AuthenticationStateChanged;
public AuthService(HttpClient httpClient, IJSRuntime jsRuntime)
public AuthService(HttpClient httpClient, IJSRuntime jsRuntime, TokenProvider tokenProvider)
{
_httpClient = httpClient;
_jsRuntime = jsRuntime;
_tokenProvider = tokenProvider;
}
public bool IsAuthenticated => _isAuthenticated ?? false;
@@ -44,6 +46,7 @@ public class AuthService
if (result != null)
{
_apiToken = result.Token;
_tokenProvider.Token = result.Token; // Set token for SignalR
_userInfo = new UserInfo
{
Id = result.Id,
@@ -104,6 +107,7 @@ public class AuthService
if (_isAuthenticated.Value && !string.IsNullOrEmpty(userInfoJson))
{
_apiToken = token;
_tokenProvider.Token = token; // Set token for SignalR
_userInfo = JsonSerializer.Deserialize<UserInfo>(userInfoJson);
// Restore header
@@ -111,14 +115,17 @@ public class AuthService
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);
Console.WriteLine($"✅ Session restored: {_userInfo?.Email}");
// Notify that authentication state changed (for SignalR initialization)
AuthenticationStateChanged?.Invoke(true);
}
else
{
Console.WriteLine("❌ No valid session");
}
Console.WriteLine($"=== AuthService.CheckAuthenticationAsync END (authenticated={_isAuthenticated}) ===");
return _isAuthenticated.Value;
}
catch (Exception ex)
@@ -139,11 +146,12 @@ public class AuthService
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", "user_info");
_apiToken = null;
_tokenProvider.Token = null; // Clear token for SignalR
_isAuthenticated = false;
_userInfo = null;
_httpClient.DefaultRequestHeaders.Authorization = null;
Console.WriteLine("✅ Authentication cleared");
AuthenticationStateChanged?.Invoke(false);
}