-
-
Notifications
You must be signed in to change notification settings - Fork 545
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
Conversation
enhenced user lookup by phone with phone number normalization.
COMPARE TO
|
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 |
There was a problem hiding this 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. |
packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/password.test.ts
Outdated
Show resolved
Hide resolved
fix typo `
clean up typos
packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/password.test.ts
Outdated
Show resolved
Hide resolved
remove test case skip statement and update changeset subject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changeset LGTM
fix typo
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:
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:
related github issue #7371.
Testing
Integration tests and unit tests added
Checklist
.changeset