Skip to content

feat(core): enhanced user lookup by phone number #7382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 14, 2025

Conversation

simeng-li
Copy link
Contributor

Summary

Enhanced user lookup by phone with phone number normalization.

In some countries, local phone numbers are often entered with a leading '0'. However, in the context of the international format this leading '0' should be stripped. E.g., +61 (0)2 1234 5678 should be normalized to +61 2 1234 5678.

In the previous implementation, Logto did not normalize the user's phone number during the user sign-up process. Both 61021345678 and 61212345678 were considered as valid phone numbers, and we do not normalize them before storing them in the database. This could lead to confusion when users try to sign-in with their phone numbers, as they may not remember the exact format they used during sign-up. Users may also end up with different accounts for the same phone number, depending on how they entered it during sign-up.

To address this issue, especially for legacy users, we have added a new enhanced user lookup by phone with either format (with or without leading '0') to the user sign-in process. This means that users can now sign-in with either format of their phone number, and Logto will try to match it with the one stored in the database, even if they might have different formats. This will help to reduce confusion and improve the user experience when logging in with phone numbers.

For example:

  • If a user signs up with the phone number +61 2 1234 5678, they can now sign-in with either +61 2 1234 5678 or +61 02 1234 5678.
  • The same applies to the phone number +61 02 1234 5678, which can be used to sign-in with either +61 2 1234 5678 or +61 02 1234 5678.

For users who might have created two different counts with the same phone number but different formats. The lookup process will always return the one with an exact match. This means that if a user has two accounts with the same phone number but different formats, they will still be able to sign-in with either format, but they will only be able to access the account that matches the format they used during sign-up.

For example:

  • If a user has two accounts with the phone numbers +61 2 1234 5678 and +61 02 1234 5678. They will need to sign-in to each account using the exact format they used during sign-up.

related github issue #7371.

Testing

Integration tests and unit tests added

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

enhenced user lookup by phone with phone number normalization.
@simeng-li simeng-li requested review from a team and Copilot May 13, 2025 10:22
@github-actions github-actions bot added the feature Cool stuff label May 13, 2025
Copy link

github-actions bot commented May 13, 2025

COMPARE TO master

Total Size Diff ⚠️ 📈 +13.41 KB

Diff by File
Name Diff
.changeset/nice-houses-sneeze.md 📈 +2.25 KB
packages/core/src/libraries/social.ts 📈 +20 Bytes
packages/core/src/queries/user.ts 📈 +2.88 KB
packages/core/src/routes/experience/classes/utils.ts 📈 +10 Bytes
packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/password.test.ts 📈 +2.18 KB
packages/shared/src/utils/phone.test.ts 📈 +3.05 KB
packages/shared/src/utils/phone.ts 📈 +3.02 KB

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements enhanced user lookup by phone number with normalization, ensuring that phone numbers entered with or without a leading zero are matched correctly during sign-in. The key changes include updates to phone number parsing and normalization utilities, new tests for phone normalization, modifications in user queries and social library for normalized phone lookup, and an updated changeset.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/shared/src/utils/phone.ts Added parsing utilities and a PhoneNumberParser class for normalization.
packages/shared/src/utils/phone.test.ts Added test cases to verify phone normalization behavior.
packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/password.test.ts Added integration tests covering various phone sign-in scenarios; one suite has been skipped and a debug statement remains.
packages/core/src/routes/experience/classes/utils.ts Updated user lookup to use the normalized phone query.
packages/core/src/queries/user.ts Introduced findUserByNormalizedPhone with normalization logic.
packages/core/src/libraries/social.ts Modified social library to use normalized phone lookup.
.changeset/nice-houses-sneeze.md Updated changeset documentation with details on phone normalization.

remove test case skip statement and update changeset subject
Copy link
Member

@gao-sun gao-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeset LGTM

@simeng-li simeng-li merged commit 4941483 into master May 14, 2025
34 checks passed
@simeng-li simeng-li deleted the simeng-phone-number-sanitisation branch May 14, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

5 participants