From a1bd5f0f5281bb23787fb87bf9439486a8cb91b5 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 22 Jun 2025 10:31:15 -0400 Subject: [PATCH] fix logging in to an existing account with different token --- packages/frontend/src/accounts.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/accounts.ts b/packages/frontend/src/accounts.ts index c7843ddb7e..751692ed68 100644 --- a/packages/frontend/src/accounts.ts +++ b/packages/frontend/src/accounts.ts @@ -40,7 +40,18 @@ export async function getAccounts(): Promise<{ } async function addAccount(host: string, user: Misskey.entities.User, token: AccountWithToken['token']) { - if (!prefer.s.accounts.some(x => x[0] === host && x[1].id === user.id)) { + // Check for duplicate accounts + if (prefer.s.accounts.some(x => x[0] === host && x[1].id === user.id)) { + if (store.s.accountTokens[host + '/' + user.id] !== token) { + // Replace account if the token changed + await removeAccount(host, user.id); + } else { + console.debug(`Not adding account ${host}/${user.id}: already logged in with same token.`); + return; + } + } + + { store.set('accountTokens', { ...store.s.accountTokens, [host + '/' + user.id]: token }); store.set('accountInfos', { ...store.s.accountInfos, [host + '/' + user.id]: user }); prefer.commit('accounts', [...prefer.s.accounts, [host, { id: user.id, username: user.username }]]);