Skip to content

Commit a0f37ef

Browse files
fix(ui): Format safe identifier phone number during sign in verification step (#3751)
1 parent e884aad commit a0f37ef

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/ui/src/components/sign-in/sign-in.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Icon from '~/primitives/icon';
2424
import { LinkButton } from '~/primitives/link-button';
2525
import { SecondaryButton } from '~/primitives/secondary-button';
2626
import { Seperator } from '~/primitives/seperator';
27+
import { formatSafeIdentifier } from '~/utils/format-safe-identifier';
2728

2829
export function SignInComponent() {
2930
return (
@@ -204,7 +205,11 @@ export function SignInComponentLoaded() {
204205
<Card.Description>{t('signIn.password.subtitle')}</Card.Description>
205206
<Card.Description>
206207
<span className='flex items-center justify-center gap-2'>
207-
<SignIn.SafeIdentifier />
208+
<SignIn.SafeIdentifier
209+
transform={val => {
210+
return formatSafeIdentifier(val) || val;
211+
}}
212+
/>
208213
<SignIn.Action
209214
navigate='start'
210215
asChild
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { stringToFormattedPhoneString } from '~/common/phone-number-field/utils';
2+
3+
export const isMaskedIdentifier = (str: string | undefined | null) => str && str.includes('**');
4+
5+
/**
6+
* Formats a string that can contain an email, a username or a phone number.
7+
* Depending on the scenario, the string might be obfuscated (parts of the identifier replaced with "*")
8+
* Refer to the tests for examples.
9+
*/
10+
export const formatSafeIdentifier = (str: string | undefined | null) => {
11+
if (!str || str.includes('@') || isMaskedIdentifier(str) || str.match(/[a-zA-Z]/)) {
12+
return str;
13+
}
14+
return stringToFormattedPhoneString(str);
15+
};

0 commit comments

Comments
 (0)