Skip to content

Commit 50a8622

Browse files
feat(clerk-js,types): Add support for additional fields for SignUp (#6716)
Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
1 parent 54b4b5a commit 50a8622

4 files changed

Lines changed: 107 additions & 9 deletions

File tree

.changeset/pink-cows-stop.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
[Experimental] Add support for additional params for SignUp

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

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
SignUpFuturePhoneCodeVerifyParams,
2626
SignUpFutureResource,
2727
SignUpFutureSSOParams,
28+
SignUpFutureUpdateParams,
2829
SignUpIdentificationField,
2930
SignUpJSON,
3031
SignUpJSONSnapshot,
@@ -132,6 +133,14 @@ export class SignUp extends BaseResource implements SignUpResource {
132133
*/
133134
__internal_basePost = this._basePost.bind(this);
134135

136+
/**
137+
* @internal Only used for internal purposes, and is not intended to be used directly.
138+
*
139+
* This property is used to provide access to underlying Client methods to `SignUpFuture`, which wraps an instance
140+
* of `SignUp`.
141+
*/
142+
__internal_basePatch = this._basePatch.bind(this);
143+
135144
constructor(data: SignUpJSON | SignUpJSONSnapshot | null = null) {
136145
super();
137146
this.fromJSON(data);
@@ -584,12 +593,62 @@ class SignUpFuture implements SignUpFutureResource {
584593
}
585594

586595
async create(params: SignUpFutureCreateParams): Promise<{ error: unknown }> {
587-
const { transfer } = params;
588596
return runAsyncResourceTask(this.resource, async () => {
589597
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
598+
599+
const body: Record<string, unknown> = {
600+
transfer: params.transfer,
601+
captchaToken,
602+
captchaWidgetType,
603+
captchaError,
604+
};
605+
606+
if (params.firstName) {
607+
body.firstName = params.firstName;
608+
}
609+
610+
if (params.lastName) {
611+
body.lastName = params.lastName;
612+
}
613+
614+
if (params.unsafeMetadata) {
615+
body.unsafeMetadata = normalizeUnsafeMetadata(params.unsafeMetadata);
616+
}
617+
618+
if (typeof params.legalAccepted !== 'undefined') {
619+
body.legalAccepted = params.legalAccepted;
620+
}
621+
590622
await this.resource.__internal_basePost({
591623
path: this.resource.pathRoot,
592-
body: { transfer, captchaToken, captchaWidgetType, captchaError },
624+
body,
625+
});
626+
});
627+
}
628+
629+
async update(params: SignUpFutureUpdateParams): Promise<{ error: unknown }> {
630+
return runAsyncResourceTask(this.resource, async () => {
631+
const body: Record<string, unknown> = {};
632+
633+
if (params.firstName) {
634+
body.firstName = params.firstName;
635+
}
636+
637+
if (params.lastName) {
638+
body.lastName = params.lastName;
639+
}
640+
641+
if (params.unsafeMetadata) {
642+
body.unsafeMetadata = normalizeUnsafeMetadata(params.unsafeMetadata);
643+
}
644+
645+
if (typeof params.legalAccepted !== 'undefined') {
646+
body.legalAccepted = params.legalAccepted;
647+
}
648+
649+
await this.resource.__internal_basePatch({
650+
path: this.resource.pathRoot,
651+
body,
593652
});
594653
});
595654
}
@@ -618,7 +677,26 @@ class SignUpFuture implements SignUpFutureResource {
618677
body.username = params.username;
619678
}
620679

621-
await this.resource.__internal_basePost({ path: this.resource.pathRoot, body });
680+
if (params.firstName) {
681+
body.firstName = params.firstName;
682+
}
683+
684+
if (params.lastName) {
685+
body.lastName = params.lastName;
686+
}
687+
688+
if (params.unsafeMetadata) {
689+
body.unsafeMetadata = normalizeUnsafeMetadata(params.unsafeMetadata);
690+
}
691+
692+
if (typeof params.legalAccepted !== 'undefined') {
693+
body.legalAccepted = params.legalAccepted;
694+
}
695+
696+
await this.resource.__internal_basePost({
697+
path: this.resource.pathRoot,
698+
body,
699+
});
622700
});
623701
}
624702

packages/react/src/stateProxy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class StateProxy implements State {
8888
},
8989

9090
create: gateMethod(target, 'create'),
91+
update: gateMethod(target, 'update'),
9192
sso: gateMethod(target, 'sso'),
9293
password: gateMethod(target, 'password'),
9394
finalize: gateMethod(target, 'finalize'),

packages/types/src/signUpFuture.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ import type { SetActiveNavigate } from './clerk';
22
import type { PhoneCodeChannel } from './phoneCodeChannel';
33
import type { SignUpIdentificationField, SignUpStatus } from './signUpCommon';
44

5-
export interface SignUpFutureCreateParams {
5+
interface SignUpFutureAdditionalParams {
6+
firstName?: string;
7+
lastName?: string;
8+
unsafeMetadata?: SignUpUnsafeMetadata;
9+
legalAccepted?: boolean;
10+
}
11+
12+
export interface SignUpFutureCreateParams extends SignUpFutureAdditionalParams {
613
transfer?: boolean;
714
}
815

16+
// This will likely get more properties
17+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
18+
export interface SignUpFutureUpdateParams extends SignUpFutureAdditionalParams {}
19+
920
export interface SignUpFutureEmailCodeVerifyParams {
1021
code: string;
1122
}
1223

13-
export type SignUpFuturePasswordParams = {
24+
export type SignUpFuturePasswordParams = SignUpFutureAdditionalParams & {
1425
password: string;
1526
} & (
16-
| { emailAddress: string; phoneNumber?: string; username?: string }
17-
| { emailAddress?: string; phoneNumber: string; username?: string }
18-
| { emailAddress?: string; phoneNumber?: string; username: string }
19-
);
27+
| { emailAddress: string; phoneNumber?: string; username?: string }
28+
| { emailAddress?: string; phoneNumber: string; username?: string }
29+
| { emailAddress?: string; phoneNumber?: string; username: string }
30+
);
2031

2132
export interface SignUpFuturePhoneCodeSendParams {
2233
phoneNumber?: string;
@@ -67,6 +78,8 @@ export interface SignUpFutureResource {
6778

6879
create: (params: SignUpFutureCreateParams) => Promise<{ error: unknown }>;
6980

81+
update: (params: SignUpFutureUpdateParams) => Promise<{ error: unknown }>;
82+
7083
/**
7184
*
7285
*/

0 commit comments

Comments
 (0)