Skip to content

Commit 68ed585

Browse files
authored
fix(clerk-js): Send ticket value from query after handling error (#6143)
1 parent 12c3826 commit 68ed585

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

.changeset/chubby-pumas-sink.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+
Fixed issues causing incorrect form fields or restricted access for users with existing sign-up tickets

packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,19 @@ function SignUpStartInternal(): JSX.Element {
116116
} as const;
117117

118118
const hasTicket = !!formState.ticket.value;
119+
const hasExistingSignUpWithTicket = !!(
120+
signUp.id &&
121+
signUp.status !== null &&
122+
(getClerkQueryParam('__clerk_ticket') || getClerkQueryParam('__clerk_invitation_token'))
123+
);
119124
const hasEmail = !!formState.emailAddress.value;
120125
const isProgressiveSignUp = userSettings.signUp.progressive;
121126
const isLegalConsentEnabled = userSettings.signUp.legal_consent_enabled;
122127
const oidcPrompt = ctx.oidcPrompt;
123128

124129
const fields = determineActiveFields({
125130
attributes,
126-
hasTicket,
131+
hasTicket: hasTicket || hasExistingSignUpWithTicket,
127132
hasEmail,
128133
activeCommIdentifierType,
129134
isProgressiveSignUp,
@@ -243,7 +248,7 @@ function SignUpStartInternal(): JSX.Element {
243248
fieldsToSubmit.push({ id: 'unsafeMetadata', value: unsafeMetadata } as any);
244249
}
245250

246-
if (fields.ticket) {
251+
if (fields.ticket || hasExistingSignUpWithTicket) {
247252
const noop = () => {};
248253
// fieldsToSubmit: Constructing a fake fields object for strategy.
249254
fieldsToSubmit.push({
@@ -254,6 +259,21 @@ function SignUpStartInternal(): JSX.Element {
254259
onChange: noop,
255260
setError: noop,
256261
} as any);
262+
263+
// Get ticket value from query params if it exists
264+
if (!fields.ticket && hasExistingSignUpWithTicket) {
265+
const ticketValue = getClerkQueryParam('__clerk_ticket') || getClerkQueryParam('__clerk_invitation_token');
266+
if (ticketValue) {
267+
fieldsToSubmit.push({
268+
id: 'ticket',
269+
value: ticketValue,
270+
clearFeedback: noop,
271+
setValue: noop,
272+
onChange: noop,
273+
setError: noop,
274+
} as any);
275+
}
276+
}
257277
}
258278

259279
// If the user has already selected an alternative phone code provider, we use that.
@@ -299,7 +319,7 @@ function SignUpStartInternal(): JSX.Element {
299319
const redirectUrlComplete = ctx.afterSignUpUrl || '/';
300320

301321
let signUpAttempt: Promise<SignUpResource>;
302-
if (!fields.ticket) {
322+
if (!fields.ticket && !hasExistingSignUpWithTicket) {
303323
signUpAttempt = signUp.create(buildRequest(fieldsToSubmit));
304324
} else {
305325
signUpAttempt = signUp.upsert(buildRequest(fieldsToSubmit));
@@ -331,9 +351,11 @@ function SignUpStartInternal(): JSX.Element {
331351
const shouldShowForm = showFormFields(userSettings) && visibleFields.length > 0;
332352

333353
const showOauthProviders =
334-
(!hasTicket || missingRequirementsWithTicket) && userSettings.authenticatableSocialStrategies.length > 0;
335-
const showWeb3Providers = !hasTicket && userSettings.web3FirstFactors.length > 0;
336-
const showAlternativePhoneCodeProviders = !hasTicket && userSettings.alternativePhoneCodeChannels.length > 0;
354+
(!(hasTicket || hasExistingSignUpWithTicket) || missingRequirementsWithTicket) &&
355+
userSettings.authenticatableSocialStrategies.length > 0;
356+
const showWeb3Providers = !(hasTicket || hasExistingSignUpWithTicket) && userSettings.web3FirstFactors.length > 0;
357+
const showAlternativePhoneCodeProviders =
358+
!(hasTicket || hasExistingSignUpWithTicket) && userSettings.alternativePhoneCodeChannels.length > 0;
337359

338360
const onAlternativePhoneCodeUseAnotherMethod = () => {
339361
setAlternativePhoneCodeProvider(null);
@@ -344,7 +366,7 @@ function SignUpStartInternal(): JSX.Element {
344366
setAlternativePhoneCodeProvider(phoneCodeProvider);
345367
};
346368

347-
if (mode !== SIGN_UP_MODES.PUBLIC && !hasTicket) {
369+
if (mode !== SIGN_UP_MODES.PUBLIC && !(hasTicket || hasExistingSignUpWithTicket)) {
348370
return <SignUpRestrictedAccess />;
349371
}
350372

0 commit comments

Comments
 (0)