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:
@@ -81,6 +81,26 @@ export async function listLocalGames(): Promise<LocalGameRecord[]> {
|
||||
}
|
||||
}
|
||||
|
||||
/** repointLocalGameSeats rewrites the account id on every stored game's seats from oldId to
|
||||
* newId. It is run when an account merge retires the account a device-local game was seated
|
||||
* under (a guest that logged into a durable account): the surviving account then owns the
|
||||
* games, so the lobby and the game header identify "me" again — without it the human seat no
|
||||
* longer matches the active account and the game shows every seat as an opponent. Best-effort;
|
||||
* the records read from IndexedDB are plain objects, so mutating and re-saving them is safe. */
|
||||
export async function repointLocalGameSeats(oldId: string, newId: string): Promise<void> {
|
||||
if (!oldId || !newId || oldId === newId) return;
|
||||
for (const g of await listLocalGames()) {
|
||||
let touched = false;
|
||||
for (const s of g.seats) {
|
||||
if (s.accountId === oldId) {
|
||||
s.accountId = newId;
|
||||
touched = true;
|
||||
}
|
||||
}
|
||||
if (touched) await saveLocalGame(g);
|
||||
}
|
||||
}
|
||||
|
||||
/** deleteLocalGame removes a game record, swallowing any failure (best-effort). */
|
||||
export async function deleteLocalGame(id: string): Promise<void> {
|
||||
const db = openDb();
|
||||
|
||||
Reference in New Issue
Block a user