From d1dff8b7956ebd4b1fe8d4dec8ece20279c080d6 Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Tue, 17 Dec 2024 13:20:43 -0500 Subject: [PATCH 1/4] feat(clerk-js): Support collecting optional fields in combined flow --- .../SignIn/handleCombinedFlowTransfer.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts index 0a883497b9..e879d2868e 100644 --- a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts +++ b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts @@ -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'; @@ -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) { @@ -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, @@ -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; +} From b3813afb8c2d918b9b9b282674ad0a8040af83ba Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Tue, 17 Dec 2024 15:40:44 -0500 Subject: [PATCH 2/4] Update handleCombinedFlowTransfer.ts --- .../ui/components/SignIn/handleCombinedFlowTransfer.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts index e879d2868e..77615fd7c4 100644 --- a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts +++ b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts @@ -45,8 +45,6 @@ export function handleCombinedFlowTransfer({ return navigate(waitlistUrl); } - console.log(clerk.client.signUp); - clerk.client.signUp[identifierAttribute] = identifierValue; const paramsToForward = new URLSearchParams(); if (organizationTicket) { @@ -82,7 +80,12 @@ export function handleCombinedFlowTransfer({ function hasOptionalFields(signUp: SignUpResource) { const filteredFields = signUp.optionalFields.filter( - field => !field.startsWith('oauth_') && !field.startsWith('web3_'), + field => + !field.startsWith('oauth_') && + !field.startsWith('web3_') && + field !== 'password' && + field !== 'enterprise_sso' && + field !== 'saml', ); return filteredFields.length > 0; } From db1f00661f26413d5ad8de98afce7078956c74f4 Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Tue, 17 Dec 2024 15:41:40 -0500 Subject: [PATCH 3/4] Update handleCombinedFlowTransfer.ts --- .../src/ui/components/SignIn/handleCombinedFlowTransfer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts index 77615fd7c4..bad25a763d 100644 --- a/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts +++ b/packages/clerk-js/src/ui/components/SignIn/handleCombinedFlowTransfer.ts @@ -51,7 +51,7 @@ 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 ( (!hasOptionalFields(clerk.client.signUp) && identifierAttribute === 'emailAddress') || From 2d3c405c452185f69ce8fa0e089323346fb5e8be Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Tue, 17 Dec 2024 15:45:09 -0500 Subject: [PATCH 4/4] add changeset --- .changeset/twelve-goats-shake.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/twelve-goats-shake.md diff --git a/.changeset/twelve-goats-shake.md b/.changeset/twelve-goats-shake.md new file mode 100644 index 0000000000..7e5b9d9922 --- /dev/null +++ b/.changeset/twelve-goats-shake.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Redirect to sign up start step within combined flow when there are optional fields.