From 2a233b2b1e631d0cb06c7b5b1f8c2adb61a49588 Mon Sep 17 00:00:00 2001 From: Toutsu Date: Mon, 25 May 2026 15:19:08 +0300 Subject: [PATCH] fix: ensure Telegram is always primary in identity links When a Discord user linked Telegram via the Telegram Login Widget, LinkIdentityAsync incorrectly made Discord primary and Telegram secondary. This broke access to all Telegram groups/sessions because ResolveEffectivePlayerIdAsync returned the (empty) Discord primary. - In /auth/telegram callback, swap LinkIdentityAsync args so Telegram is always treated as the current (primary) account. - Add V022 migration to reverse any existing incorrectly-oriented player_links where Discord is primary and Telegram is secondary. Co-Authored-By: Claude Opus 4.7 --- .../V022__fix_discord_telegram_links.sql | 16 ++++++++++++++++ src/GmRelay.Web/Program.cs | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/GmRelay.Bot/Migrations/V022__fix_discord_telegram_links.sql diff --git a/src/GmRelay.Bot/Migrations/V022__fix_discord_telegram_links.sql b/src/GmRelay.Bot/Migrations/V022__fix_discord_telegram_links.sql new file mode 100644 index 0000000..5ff5aad --- /dev/null +++ b/src/GmRelay.Bot/Migrations/V022__fix_discord_telegram_links.sql @@ -0,0 +1,16 @@ +-- ============================================================= +-- V022: Fix incorrectly oriented player_links for Discord↔Telegram +-- ============================================================= +-- Scope: Reverse player_links where Discord was incorrectly made primary +-- and Telegram secondary. Telegram (with historical group/session data) +-- must always be the primary account. +-- ============================================================= + +UPDATE player_links pl +SET primary_player_id = pl.secondary_player_id, + secondary_player_id = pl.primary_player_id +FROM players p1, players p2 +WHERE pl.primary_player_id = p1.id + AND pl.secondary_player_id = p2.id + AND p1.platform = 'Discord' + AND p2.platform = 'Telegram'; diff --git a/src/GmRelay.Web/Program.cs b/src/GmRelay.Web/Program.cs index 15e8d65..8d16f9d 100644 --- a/src/GmRelay.Web/Program.cs +++ b/src/GmRelay.Web/Program.cs @@ -137,9 +137,10 @@ app.MapGet("/auth/telegram", async (HttpContext context, TelegramAuthService aut { try { + // Always make Telegram the primary (it has the historical data/groups) await sessionStore.LinkIdentityAsync( - currentPlatform, currentExternalUserId, "Telegram", telegramId.ToString(System.Globalization.CultureInfo.InvariantCulture), + currentPlatform, currentExternalUserId, name); return Results.Redirect("/profile?linked=telegram"); }