diff --git a/src/NexusReader.UI.Shared/Layout/MainHubLayout.razor b/src/NexusReader.UI.Shared/Layout/MainHubLayout.razor index 744c143..792c199 100644 --- a/src/NexusReader.UI.Shared/Layout/MainHubLayout.razor +++ b/src/NexusReader.UI.Shared/Layout/MainHubLayout.razor @@ -85,6 +85,14 @@ private bool _isSyncing = false; + protected override void OnAfterRender(bool firstRender) + { + if (firstRender) + { + Console.WriteLine($"[MainHubLayout] Rendered. IsBrowser: {System.OperatingSystem.IsBrowser()}"); + } + } + protected override async Task OnInitializedAsync() { if (_isSyncing) return; diff --git a/src/NexusReader.UI.Shared/Pages/Account/Profile.razor b/src/NexusReader.UI.Shared/Pages/Account/Profile.razor index 511ce76..0681c6b 100644 --- a/src/NexusReader.UI.Shared/Pages/Account/Profile.razor +++ b/src/NexusReader.UI.Shared/Pages/Account/Profile.razor @@ -110,7 +110,9 @@ protected override async Task OnInitializedAsync() { + Console.WriteLine("[Profile] Initializing..."); _profile = await IdentityService.GetProfileAsync(); + Console.WriteLine($"[Profile] Profile loaded: {_profile?.Email ?? "NULL"}"); StateHasChanged(); } diff --git a/src/NexusReader.UI.Shared/Services/IdentityService.cs b/src/NexusReader.UI.Shared/Services/IdentityService.cs index 79d71c8..5ca6764 100644 --- a/src/NexusReader.UI.Shared/Services/IdentityService.cs +++ b/src/NexusReader.UI.Shared/Services/IdentityService.cs @@ -121,14 +121,17 @@ public class IdentityService : IIdentityService { if (_cachedProfile != null) { + Console.WriteLine("[IdentityService] Returning cached profile."); return _cachedProfile; } if (_profileTask != null) { + Console.WriteLine("[IdentityService] Awaiting existing profile task..."); return await _profileTask; } + Console.WriteLine("[IdentityService] Starting new profile fetch task..."); _profileTask = GetProfileInternalAsync(); return await _profileTask; } @@ -139,11 +142,13 @@ public class IdentityService : IIdentityService { if (!System.OperatingSystem.IsBrowser()) { + Console.WriteLine("[IdentityService] Skipping profile fetch: Not in browser."); return null; } if (DateTime.UtcNow - _lastFetchAttempt < TimeSpan.FromSeconds(5)) { + Console.WriteLine("[IdentityService] Skipping profile fetch: Throttled."); return null; } @@ -151,18 +156,23 @@ public class IdentityService : IIdentityService try { var response = await _httpClient.GetAsync("identity/profile"); + Console.WriteLine($"[IdentityService] Profile response: {response.StatusCode}"); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { + Console.WriteLine("[IdentityService] Unauthorized. Logging out..."); await LogoutAsync(); return null; } if (response.IsSuccessStatusCode) { + var content = await response.Content.ReadAsStringAsync(); + Console.WriteLine($"[IdentityService] Raw content: {content}"); var profile = await response.Content.ReadFromJsonAsync(); if (profile != null) { + Console.WriteLine($"[IdentityService] Profile fetched: {profile.Email}"); _cachedProfile = profile; await _storageService.SaveSecureString("nexus_user_email", profile.Email); await _storageService.SaveSecureString("nexus_user_tenant", profile.TenantId.ToString()); @@ -173,8 +183,9 @@ public class IdentityService : IIdentityService return null; } - catch + catch (Exception ex) { + Console.WriteLine($"[IdentityService] ERROR: {ex.Message}"); return null; } finally