diff --git a/packages/clerk-js/src/core/resources/SignUp.ts b/packages/clerk-js/src/core/resources/SignUp.ts index 5586e77e86..66b0d81db9 100644 --- a/packages/clerk-js/src/core/resources/SignUp.ts +++ b/packages/clerk-js/src/core/resources/SignUp.ts @@ -367,6 +367,10 @@ export class SignUp extends BaseResource implements SignUpResource { }); }; + upsert = (params: SignUpCreateParams | SignUpUpdateParams): Promise => { + return this.id ? this.update(params) : this.create(params); + }; + validatePassword: ReturnType = (password, cb) => { if (SignUp.clerk.__unstable__environment?.userSettings.passwordSettings) { return createValidatePassword({ diff --git a/packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx b/packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx index 700d4b24ba..706962288c 100644 --- a/packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx +++ b/packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx @@ -232,10 +232,8 @@ function _SignUpStart(): JSX.Element { const redirectUrl = buildSSOCallbackURL(ctx, displayConfig.signUpUrl); const redirectUrlComplete = ctx.afterSignUpUrl || '/'; - const requestParams = buildRequest(fieldsToSubmit); - const signUpRequest = signUp.id ? signUp.update(requestParams) : signUp.create(requestParams); - - return signUpRequest + return signUp + .upsert(buildRequest(fieldsToSubmit)) .then(res => completeSignUpFlow({ signUp: res, diff --git a/packages/types/src/signUp.ts b/packages/types/src/signUp.ts index b98fec79a2..b40a3eb448 100644 --- a/packages/types/src/signUp.ts +++ b/packages/types/src/signUp.ts @@ -66,6 +66,8 @@ export interface SignUpResource extends ClerkResource { update: (params: SignUpUpdateParams) => Promise; + upsert: (params: SignUpCreateParams | SignUpUpdateParams) => Promise; + prepareVerification: (params: PrepareVerificationParams) => Promise; attemptVerification: (params: AttemptVerificationParams) => Promise;