From 23ef7e3ded87328386ee69dd454c343e28aa55ff Mon Sep 17 00:00:00 2001 From: REDCODE Date: Wed, 8 Jul 2026 19:15:49 +0200 Subject: [PATCH] fix(auth): detect banned/deleted user on page load via InitializeAsync - LoginService.InitializeAsync: after fetching LoggedUser, check IsBanned and DeletedAt. If banned/disabled, set ForceLogoutReason, call Logout to clear state, and return false - App.razor: after InitializeAsync completes, check ForceLogoutReason and navigate to /login if set. This handles the timing issue where MainLayout isnt created yet when the event fires on page load Refs #45 --- MilkStream.Client/Components/App.razor | 4 ++++ MilkStream.Client/Services/LoginService.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/MilkStream.Client/Components/App.razor b/MilkStream.Client/Components/App.razor index fba8395..96103ac 100644 --- a/MilkStream.Client/Components/App.razor +++ b/MilkStream.Client/Components/App.razor @@ -1,4 +1,5 @@ @inject LoginService loginService +@inject NavigationManager NavigationManager @if (_initialized) { @@ -20,5 +21,8 @@ protected override async Task OnInitializedAsync() { await loginService.InitializeAsync(); _initialized = true; + + if (loginService.ForceLogoutReason != null) + NavigationManager.NavigateTo("/login", true); } } diff --git a/MilkStream.Client/Services/LoginService.cs b/MilkStream.Client/Services/LoginService.cs index 0f66768..47e8aca 100644 --- a/MilkStream.Client/Services/LoginService.cs +++ b/MilkStream.Client/Services/LoginService.cs @@ -112,6 +112,19 @@ public sealed class LoginService : ServiceBase { AuthInfo = auth; LoggedUser = await FetchLoggedUserAsync(); + + if (LoggedUser is { IsBanned: true }) { + ForceLogoutReason = "User is banned"; + await Logout(); + return false; + } + + if (LoggedUser is { DeletedAt: not null }) { + ForceLogoutReason = "User is disabled"; + await Logout(); + return false; + } + return IsLoggedIn; }