Skip to content

Commit 6e09656

Browse files
authoredJan 23, 2025
fix(clerk-js,types): Reuse existing sign-up if available (#4720)
1 parent e0cea9a commit 6e09656

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed
 

‎.changeset/purple-foxes-develop.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
- Introduced an `upsert` method to the `SignUp` resource, which reuses the existing sign-up attempt ID if it exists.
7+
- Fix a ticket flow issue on `<SignUp />` component, where in some rare cases the initial ticket/context is lost, because of creating a new sign-up attempt ID.

‎packages/clerk-js/src/core/resources/SignUp.ts

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ export class SignUp extends BaseResource implements SignUpResource {
339339
});
340340
};
341341

342+
upsert = (params: SignUpCreateParams | SignUpUpdateParams): Promise<SignUpResource> => {
343+
return this.id ? this.update(params) : this.create(params);
344+
};
345+
342346
validatePassword: ReturnType<typeof createValidatePassword> = (password, cb) => {
343347
if (SignUp.clerk.__unstable__environment?.userSettings.passwordSettings) {
344348
return createValidatePassword({

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,14 @@ function _SignUpStart(): JSX.Element {
218218
if (fields.ticket) {
219219
const noop = () => {};
220220
// fieldsToSubmit: Constructing a fake fields object for strategy.
221-
fieldsToSubmit.push({ id: 'strategy', value: 'ticket', setValue: noop, onChange: noop, setError: noop } as any);
221+
fieldsToSubmit.push({
222+
id: 'strategy',
223+
value: 'ticket',
224+
clearFeedback: noop,
225+
setValue: noop,
226+
onChange: noop,
227+
setError: noop,
228+
} as any);
222229
}
223230

224231
// In case of emailOrPhone (both email & phone are optional) and neither of them is provided,
@@ -238,7 +245,7 @@ function _SignUpStart(): JSX.Element {
238245
const redirectUrlComplete = ctx.afterSignUpUrl || '/';
239246

240247
return signUp
241-
.create(buildRequest(fieldsToSubmit))
248+
.upsert(buildRequest(fieldsToSubmit))
242249
.then(res =>
243250
completeSignUpFlow({
244251
signUp: res,

‎packages/types/src/signUp.ts

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export interface SignUpResource extends ClerkResource {
6767

6868
update: (params: SignUpUpdateParams) => Promise<SignUpResource>;
6969

70+
upsert: (params: SignUpCreateParams | SignUpUpdateParams) => Promise<SignUpResource>;
71+
7072
prepareVerification: (params: PrepareVerificationParams) => Promise<SignUpResource>;
7173

7274
attemptVerification: (params: AttemptVerificationParams) => Promise<SignUpResource>;

0 commit comments

Comments
 (0)