feat(link): auto-merge a guest initiator into its durable account (seamless sign-in)
When a guest links an identity (email/TG/VK) that already belongs to a durable account, the guest-primary rule already made the durable account the survivor and switched the session — but the client still showed an irreversible 'merge two accounts?' confirmation, which is nonsense from the user's side (they are simply signing into their account). The confirm step now merges inline for a GUEST initiator and returns the completed merge (the switched token); a durable initiator still gets the explicit confirmation (consolidating two real accounts is consequential). The active-game guard still refuses, surfaced as the clear error.merge_active_game_conflict message rather than swallowed. Also fixes the merged-away device-local games: their human/host seat was recorded under the retired account id, so after the switch the lobby and game header could not identify 'me' and showed every seat as an opponent (the game still played — turn logic is seat-index based). applyLinkResult now re-points local game seats from the retired id to the survivor (repointLocalGameSeats). Docs: FUNCTIONAL.md (+_ru).
This commit is contained in:
@@ -662,7 +662,18 @@ async function reconcileServerGuest(): Promise<void> {
|
||||
*/
|
||||
export async function applyLinkResult(r: LinkResult): Promise<void> {
|
||||
if (r.session && r.session.token) {
|
||||
// A guest initiator's merge switches the session to the surviving durable account. Its
|
||||
// device-local games (vs_ai / hotseat) were seated under the retired account's id, so
|
||||
// re-point them to the survivor: the lobby and the game header identify "me" by the active
|
||||
// account, and without this the merged-away game shows every seat as an opponent (the
|
||||
// in-game turn logic is seat-index based, so it still plays — the summary just misreads).
|
||||
const retiredId = app.session?.userId;
|
||||
await adoptSession(r.session);
|
||||
const survivorId = app.session?.userId;
|
||||
if (retiredId && survivorId && retiredId !== survivorId) {
|
||||
const { repointLocalGameSeats } = await import('./localgame/store');
|
||||
await repointLocalGameSeats(retiredId, survivorId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
app.profile = await gateway.profileGet();
|
||||
|
||||
Reference in New Issue
Block a user