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 committed Dec 17, 2024
1 parent 3f98e14 commit d1dff8b
Showing 1 changed file with 14 additions and 2 deletions.
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 @@ -45,6 +45,8 @@ export function handleCombinedFlowTransfer({
return navigate(waitlistUrl);
}

console.log(clerk.client.signUp);

clerk.client.signUp[identifierAttribute] = identifierValue;
const paramsToForward = new URLSearchParams();
if (organizationTicket) {
Expand All @@ -53,7 +55,10 @@ export function handleCombinedFlowTransfer({

// Attempt to transfer directly to sign up verification if email or phone was used. 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 +79,10 @@ export function handleCombinedFlowTransfer({

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

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

0 comments on commit d1dff8b

Please sign in to comment.