Skip to content

Commit

Permalink
refactor: Move logic to class
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaspt committed Dec 5, 2024
1 parent 18af2b8 commit bf3117f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ export class SignUp extends BaseResource implements SignUpResource {
});
};

upsert = (params: SignUpCreateParams | SignUpUpdateParams): Promise<SignUpResource> => {
return this.id ? this.update(params) : this.create(params);
};

validatePassword: ReturnType<typeof createValidatePassword> = (password, cb) => {
if (SignUp.clerk.__unstable__environment?.userSettings.passwordSettings) {
return createValidatePassword({
Expand Down
6 changes: 2 additions & 4 deletions packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface SignUpResource extends ClerkResource {

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

upsert: (params: SignUpCreateParams | SignUpUpdateParams) => Promise<SignUpResource>;

prepareVerification: (params: PrepareVerificationParams) => Promise<SignUpResource>;

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

0 comments on commit bf3117f

Please sign in to comment.