Skip to content

Commit

Permalink
feat(clerk-js): Start with phone input if the only sign in initial va…
Browse files Browse the repository at this point in the history
…lue is the phone number (#1861)
  • Loading branch information
desiprisg authored Oct 12, 2023
1 parent 91e9a55 commit c04ad94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/large-rockets-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': minor
---

The sign-in form will now switch to the phone input if the only initial value provided was that of the phone number.
9 changes: 8 additions & 1 deletion packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ export function _SignInStart(): JSX.Element {
() => groupIdentifiers(userSettings.enabledFirstFactorIdentifiers),
[userSettings.enabledFirstFactorIdentifiers],
);
const [identifierAttribute, setIdentifierAttribute] = useState<SignInStartIdentifier>(identifierAttributes[0] || '');

const onlyPhoneNumberInitialValueExists =
!!ctx.initialValues?.phoneNumber && !(ctx.initialValues.emailAddress || ctx.initialValues.username);
const shouldStartWithPhoneNumberIdentifier =
onlyPhoneNumberInitialValueExists && identifierAttributes.includes('phone_number');
const [identifierAttribute, setIdentifierAttribute] = useState<SignInStartIdentifier>(
shouldStartWithPhoneNumberIdentifier ? 'phone_number' : identifierAttributes[0] || '',
);
const [hasSwitchedByAutofill, setHasSwitchedByAutofill] = useState(false);

const organizationTicket = getClerkQueryParam('__clerk_ticket') || '';
Expand Down

0 comments on commit c04ad94

Please sign in to comment.