From af37f3a8ecf03072d51de64f622c140b1ff4ccfc Mon Sep 17 00:00:00 2001 From: Toutsu Date: Mon, 25 May 2026 14:20:26 +0300 Subject: [PATCH] fix: Profile.razor use ISessionStore directly + forceLoad for Discord link - Replace HttpClient API calls with direct ISessionStore DI to avoid 302 redirect from missing auth cookie in Blazor Server interactive mode - Use NavigationManager.NavigateTo with forceLoad=true for Discord OAuth to bypass Blazor circuit navigation and trigger full HTTP request Co-Authored-By: Claude Opus 4.7 --- .../Components/Pages/Profile.razor | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/GmRelay.Web/Components/Pages/Profile.razor b/src/GmRelay.Web/Components/Pages/Profile.razor index f565102..cb7e9cd 100644 --- a/src/GmRelay.Web/Components/Pages/Profile.razor +++ b/src/GmRelay.Web/Components/Pages/Profile.razor @@ -1,9 +1,8 @@ @page "/profile" @using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Components.Authorization -@using System.Net.Http.Json @attribute [Authorize] -@inject IHttpClientFactory HttpClientFactory +@inject ISessionStore SessionStore @inject NavigationManager Navigation Профиль — GM-Relay @@ -55,9 +54,9 @@

Добавить аккаунт

@if (!HasLinkedPlatform("Discord")) { - + } else { @@ -107,9 +106,14 @@ { try { - var http = HttpClientFactory.CreateClient(); - http.BaseAddress = new Uri(Navigation.BaseUri); - identities = await http.GetFromJsonAsync>("api/me/identities"); + if (currentPlatform is not null && currentExternalUserId is not null) + { + identities = await SessionStore.GetLinkedIdentitiesAsync(currentPlatform, currentExternalUserId); + } + else + { + identities = []; + } } catch (Exception ex) { @@ -130,19 +134,19 @@ try { - var http = HttpClientFactory.CreateClient(); - http.BaseAddress = new Uri(Navigation.BaseUri); - var response = await http.DeleteAsync($"api/me/identities/{Uri.EscapeDataString(platform)}/{Uri.EscapeDataString(externalUserId)}"); - if (response.IsSuccessStatusCode) + if (currentPlatform is null || currentExternalUserId is null) { - successMessage = $"{platform} аккаунт отвязан."; - await LoadIdentities(); - } - else - { - var body = await response.Content.ReadAsStringAsync(); - errorMessage = $"Ошибка отвязки: {body}"; + errorMessage = "Не удалось определить текущего пользователя."; + return; } + + await SessionStore.UnlinkIdentityAsync(currentPlatform, currentExternalUserId, platform, externalUserId); + successMessage = $"{platform} аккаунт отвязан."; + await LoadIdentities(); + } + catch (InvalidOperationException ex) + { + errorMessage = $"Ошибка отвязки: {ex.Message}"; } catch (Exception ex) { @@ -153,4 +157,9 @@ isUnlinking = false; } } + + private void LinkDiscord() + { + Navigation.NavigateTo("/auth/discord", forceLoad: true); + } }