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); + } }