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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
<PageTitle>Профиль — GM-Relay</PageTitle>
|
||||
@@ -55,9 +54,9 @@
|
||||
<h2 class="section-title">Добавить аккаунт</h2>
|
||||
@if (!HasLinkedPlatform("Discord"))
|
||||
{
|
||||
<a class="btn btn-primary" href="/auth/discord">
|
||||
<button class="btn btn-primary" @onclick="LinkDiscord">
|
||||
Привязать Discord
|
||||
</a>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,9 +106,14 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var http = HttpClientFactory.CreateClient();
|
||||
http.BaseAddress = new Uri(Navigation.BaseUri);
|
||||
identities = await http.GetFromJsonAsync<List<LinkedIdentity>>("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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user