Skip to content

auth login: phone login fails when the user already has an account under another phone #213

Closed

Description

@neoromantic

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:

  1. tg auth login-qr as user 4242 creates the account user:4242.
  2. tg auth login --phone +15550000001 as the same user.
  3. 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

  1. added a commit that references this issue on Nov 19, 2026
    9a40597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions