Skip to content

fix(auth): phone login for a user with an account under another phone - #218

Merged
neoromantic merged 1 commit into
mainfrom
fix/phone-login-existing-user
Nov 19, 2026
Merged

neoromantic merged 1 commit into
mainfrom
fix/phone-login-existing-user

Conversation

@neoromantic

Copy link
Copy Markdown
Owner

Closes #213.

loginWithPhone creates an account for the phone, then saveLoggedInUser finds the user's older account by user_id (a QR user:<id> account or an old number) and moved the phone onto it before deleting the new account. accounts.phone is UNIQUE, so the update threw and the login failed with a second account left behind.

The new account is now deleted first. The phone belonged only to that account (it was found by getByPhone or created with it), so the update can't conflict afterwards, and no transaction is needed: a crash between the two statements leaves the older account untouched and no duplicate.

The test runs on the real accounts schema (createTestDatabase()) and failed before the fix with UNIQUE constraint failed: accounts.phone.

Checks: bun run check, bun run test, bun run test:e2e, bun run build.

🤖 Generated with Claude Code

Delete the account the login created before the phone moves to the user's
older account, so accounts.phone stays unique. Closes #213.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@neoromantic
neoromantic merged commit d612921 into main Nov 19, 2026
5 checks passed
@neoromantic
neoromantic deleted the fix/phone-login-existing-user branch November 19, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant