Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clerk-js): Support collecting optional fields in combined flow #4795

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading