From bf3117f669c82a3a0bbf636743c35b6cc72d6155 Mon Sep 17 00:00:00 2001 From: Konstantinos Pittas Date: Thu, 5 Dec 2024 20:20:49 +0200 Subject: [PATCH] refactor: Move logic to class --- packages/clerk-js/src/core/resources/SignUp.ts | 4 ++++ packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx | 6 ++---- packages/types/src/signUp.ts | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) 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;