You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
auth login: phone login fails when the user already has an account under another phone #213
tg auth login --phone fails for a Telegram user who already has an account in data.db under another phone, for example the user:<id> account a QR login creates, or a number the user has since changed.
loginWithPhone creates an account for the new phone first (src/commands/auth.ts:197). After sign-in, applyLoggedInUser finds the older account with the same user_id, calls accountsDb.update(existing.id, { phone, … }) and only then deletes the new account (src/commands/auth.ts:173-181). accounts.phone is UNIQUE, so the update throws UNIQUE constraint failed: accounts.phone. The login fails and the new account is left behind.
Steps, with made-up data:
tg auth login-qr as user 4242 creates the account user:4242.
tg auth login --phone +15550000001 as the same user.
The login fails with the constraint error, and tg accounts list shows two accounts.
A test with a hand-written accounts table, which had no unique phone, hid this. It was removed in #208. Fix: delete the new account before updating the older one, and cover it with a test on the real accounts table (createTestDatabase()).
Activity
fix(auth): phone login for a user with an account under another phone