Skip to content

Commit fbb9e0d

Browse files
feat(clerk-js): Support collecting optional fields in combined flow (#4795)
1 parent 4c6befc commit fbb9e0d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

.changeset/twelve-goats-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Redirect to sign up start step within combined flow when there are optional fields.

packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LoadedClerk, SignUpModes } from '@clerk/types';
1+
import type { LoadedClerk, SignUpModes, SignUpResource } from '@clerk/types';
22

33
import { SIGN_UP_MODES } from '../../../core/constants';
44
import { completeSignUpFlow } from '../SignUp/util';
@@ -51,9 +51,12 @@ export function handleCombinedFlowTransfer({
5151
paramsToForward.set('__clerk_ticket', organizationTicket);
5252
}
5353

54-
// Attempt to transfer directly to sign up verification if email or phone was used. The signUp.create() call will
54+
// 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
5555
// inform us if the instance is eligible for moving directly to verification.
56-
if (identifierAttribute === 'emailAddress' || identifierAttribute === 'phoneNumber') {
56+
if (
57+
(!hasOptionalFields(clerk.client.signUp) && identifierAttribute === 'emailAddress') ||
58+
identifierAttribute === 'phoneNumber'
59+
) {
5760
return clerk.client.signUp
5861
.create({
5962
[identifierAttribute]: identifierValue,
@@ -74,3 +77,15 @@ export function handleCombinedFlowTransfer({
7477

7578
return navigate(`create?${paramsToForward.toString()}`);
7679
}
80+
81+
function hasOptionalFields(signUp: SignUpResource) {
82+
const filteredFields = signUp.optionalFields.filter(
83+
field =>
84+
!field.startsWith('oauth_') &&
85+
!field.startsWith('web3_') &&
86+
field !== 'password' &&
87+
field !== 'enterprise_sso' &&
88+
field !== 'saml',
89+
);
90+
return filteredFields.length > 0;
91+
}

0 commit comments

Comments
 (0)