Skip to content

Commit

Permalink
fix(ui): Format safe identifier phone number during sign in verificat…
Browse files Browse the repository at this point in the history
…ion step (#3751)
  • Loading branch information
alexcarpenter authored Jul 18, 2024
1 parent e884aad commit a0f37ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/ui/src/components/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Icon from '~/primitives/icon';
import { LinkButton } from '~/primitives/link-button';
import { SecondaryButton } from '~/primitives/secondary-button';
import { Seperator } from '~/primitives/seperator';
import { formatSafeIdentifier } from '~/utils/format-safe-identifier';

export function SignInComponent() {
return (
Expand Down Expand Up @@ -204,7 +205,11 @@ export function SignInComponentLoaded() {
<Card.Description>{t('signIn.password.subtitle')}</Card.Description>
<Card.Description>
<span className='flex items-center justify-center gap-2'>
<SignIn.SafeIdentifier />
<SignIn.SafeIdentifier
transform={val => {
return formatSafeIdentifier(val) || val;
}}
/>
<SignIn.Action
navigate='start'
asChild
Expand Down
15 changes: 15 additions & 0 deletions packages/ui/src/utils/format-safe-identifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stringToFormattedPhoneString } from '~/common/phone-number-field/utils';

export const isMaskedIdentifier = (str: string | undefined | null) => str && str.includes('**');

/**
* Formats a string that can contain an email, a username or a phone number.
* Depending on the scenario, the string might be obfuscated (parts of the identifier replaced with "*")
* Refer to the tests for examples.
*/
export const formatSafeIdentifier = (str: string | undefined | null) => {
if (!str || str.includes('@') || isMaskedIdentifier(str) || str.match(/[a-zA-Z]/)) {
return str;
}
return stringToFormattedPhoneString(str);
};

0 comments on commit a0f37ef

Please sign in to comment.