diff --git a/src/NexusReader.UI.Shared/Services/IdentityService.cs b/src/NexusReader.UI.Shared/Services/IdentityService.cs index 0a4e672..441ea88 100644 --- a/src/NexusReader.UI.Shared/Services/IdentityService.cs +++ b/src/NexusReader.UI.Shared/Services/IdentityService.cs @@ -2,36 +2,11 @@ using System.Net.Http.Json; using Microsoft.AspNetCore.Components.Authorization; using NexusReader.Application.Abstractions.Services; using NexusReader.Application.DTOs.User; -using NexusReader.UI.Shared.Constants; +using NexusReader.Application.Constants; using FluentResults; namespace NexusReader.UI.Shared.Services; -public interface IIdentityService -{ - event Func? OnStateInvalidated; - Task RegisterAsync(string email, string password); - Task LoginAsync(string email, string password, bool rememberMe = false); - Task LogoutAsync(); - Task> GetProfileAsync(); - Task RefreshTokenAsync(); -} - -public record UserProfile( - string Email, - int AITokensUsed, - Guid TenantId, - SubscriptionPlanDto Plan, - int AverageQuizScore, - LastReadBookDto? LastReadBook, - string[] Roles) -{ - // Helper properties for UI compatibility - public string CurrentPlan => Plan?.Name ?? PlanConstants.DefaultPlanName; - public int AITokenLimit => Plan?.AITokenLimit ?? PlanConstants.DefaultTokenLimit; - public string LastReadBookTitle => LastReadBook?.Title ?? PlanConstants.DefaultActivityLabel; -} - public class IdentityService : IIdentityService { private readonly HttpClient _httpClient; @@ -39,8 +14,8 @@ public class IdentityService : IIdentityService private readonly AuthenticationStateProvider? _authStateProvider; private const string TokenKey = StorageKeys.AuthToken; private const string RefreshTokenKey = StorageKeys.RefreshToken; - private Task? _profileTask; - private UserProfile? _cachedProfile; + private Task? _profileTask; + private UserProfileDto? _cachedProfile; private DateTime _lastFetchAttempt = DateTime.MinValue; public event Func? OnStateInvalidated; @@ -152,7 +127,7 @@ public class IdentityService : IIdentityService } } - public async Task> GetProfileAsync() + public async Task> GetProfileAsync() { if (_cachedProfile != null) { @@ -172,7 +147,7 @@ public class IdentityService : IIdentityService - private async Task GetProfileInternalAsync() + private async Task GetProfileInternalAsync() { if (!System.OperatingSystem.IsBrowser()) { @@ -197,7 +172,7 @@ public class IdentityService : IIdentityService if (response.IsSuccessStatusCode) { - var profile = await response.Content.ReadFromJsonAsync(); + var profile = await response.Content.ReadFromJsonAsync(); if (profile != null) { _cachedProfile = profile;