Skip to content

Commit

Permalink
feat(clerk-js): Support collecting optional fields in combined flow (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter authored and BRKalow committed Dec 20, 2024
1 parent c462d10 commit c968885
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-goats-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Redirect to sign up start step within combined flow when there are optional fields.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LoadedClerk, SignUpModes } from '@clerk/types';
import type { LoadedClerk, SignUpModes, SignUpResource } from '@clerk/types';

import { SIGN_UP_MODES } from '../../../core/constants';
import { completeSignUpFlow } from '../SignUp/util';
Expand Down Expand Up @@ -51,9 +51,12 @@ export function handleCombinedFlowTransfer({
paramsToForward.set('__clerk_ticket', organizationTicket);
}

// Attempt to transfer directly to sign up verification if email or phone was used. The signUp.create() call will
// Attempt to transfer directly to sign up verification if email or phone was used and there are no optional fields. The signUp.create() call will
// inform us if the instance is eligible for moving directly to verification.
if (identifierAttribute === 'emailAddress' || identifierAttribute === 'phoneNumber') {
if (
(!hasOptionalFields(clerk.client.signUp) && identifierAttribute === 'emailAddress') ||
identifierAttribute === 'phoneNumber'
) {
return clerk.client.signUp
.create({
[identifierAttribute]: identifierValue,
Expand All @@ -74,3 +77,15 @@ export function handleCombinedFlowTransfer({

return navigate(`create?${paramsToForward.toString()}`);
}

function hasOptionalFields(signUp: SignUpResource) {
const filteredFields = signUp.optionalFields.filter(
field =>
!field.startsWith('oauth_') &&
!field.startsWith('web3_') &&
field !== 'password' &&
field !== 'enterprise_sso' &&
field !== 'saml',
);
return filteredFields.length > 0;
}

0 comments on commit c968885

Please sign in to comment.