Skip to content

Commit 8dc6bad

Browse files
authored
feat(clerk-js,types): Signal SignUp APIs (#6571)
1 parent 81b2759 commit 8dc6bad

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

.changeset/big-queens-tap.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] Signal SignUp APIs

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
PreparePhoneNumberVerificationParams,
1414
PrepareVerificationParams,
1515
PrepareWeb3WalletVerificationParams,
16+
SetActiveNavigate,
1617
SignUpAuthenticateWithWeb3Params,
1718
SignUpCreateParams,
1819
SignUpField,
@@ -40,6 +41,7 @@ import { _authenticateWithPopup } from '../../utils/authenticateWithPopup';
4041
import { CaptchaChallenge } from '../../utils/captcha/CaptchaChallenge';
4142
import { createValidatePassword } from '../../utils/passwords/password';
4243
import { normalizeUnsafeMetadata } from '../../utils/resourceParams';
44+
import { runAsyncResourceTask } from '../../utils/runAsyncResourceTask';
4345
import {
4446
clerkInvalidFAPIResponse,
4547
clerkMissingOptionError,
@@ -470,9 +472,55 @@ export class SignUp extends BaseResource implements SignUpResource {
470472
}
471473

472474
class SignUpFuture implements SignUpFutureResource {
475+
verifications = {
476+
sendEmailCode: this.sendEmailCode.bind(this),
477+
verifyEmailCode: this.verifyEmailCode.bind(this),
478+
};
479+
473480
constructor(readonly resource: SignUp) {}
474481

475482
get status() {
476483
return this.resource.status;
477484
}
485+
486+
get unverifiedFields() {
487+
return this.resource.unverifiedFields;
488+
}
489+
490+
async password({ emailAddress, password }: { emailAddress: string; password: string }): Promise<{ error: unknown }> {
491+
return runAsyncResourceTask(this.resource, async () => {
492+
await this.resource.__internal_basePost({
493+
path: this.resource.pathRoot,
494+
body: { emailAddress, password },
495+
});
496+
});
497+
}
498+
499+
async sendEmailCode(): Promise<{ error: unknown }> {
500+
return runAsyncResourceTask(this.resource, async () => {
501+
await this.resource.__internal_basePost({
502+
body: { strategy: 'email_code' },
503+
action: 'prepare_verification',
504+
});
505+
});
506+
}
507+
508+
async verifyEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
509+
return runAsyncResourceTask(this.resource, async () => {
510+
await this.resource.__internal_basePost({
511+
body: { strategy: 'email_code', code },
512+
action: 'attempt_verification',
513+
});
514+
});
515+
}
516+
517+
async finalize({ navigate }: { navigate?: SetActiveNavigate }): Promise<{ error: unknown }> {
518+
return runAsyncResourceTask(this.resource, async () => {
519+
if (!this.resource.createdSessionId) {
520+
throw new Error('Cannot finalize sign-up without a created session.');
521+
}
522+
523+
await SignUp.clerk.setActive({ session: this.resource.createdSessionId, navigate });
524+
});
525+
}
478526
}

packages/types/src/signUp.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PhoneCodeChannel } from 'phoneCodeChannel';
22

33
import type { FirstNameAttribute, LastNameAttribute, LegalAcceptedAttribute, PasswordAttribute } from './attributes';
4+
import type { SetActiveNavigate } from './clerk';
45
import type { AttemptEmailAddressVerificationParams, PrepareEmailAddressVerificationParams } from './emailAddress';
56
import type {
67
EmailAddressIdentifier,
@@ -120,6 +121,13 @@ export interface SignUpResource extends ClerkResource {
120121

121122
export interface SignUpFutureResource {
122123
status: SignUpStatus | null;
124+
unverifiedFields: SignUpIdentificationField[];
125+
verifications: {
126+
sendEmailCode: () => Promise<{ error: unknown }>;
127+
verifyEmailCode: (params: { code: string }) => Promise<{ error: unknown }>;
128+
};
129+
password: (params: { emailAddress: string; password: string }) => Promise<{ error: unknown }>;
130+
finalize: (params: { navigate?: SetActiveNavigate }) => Promise<{ error: unknown }>;
123131
}
124132

125133
export type SignUpStatus = 'missing_requirements' | 'complete' | 'abandoned';

0 commit comments

Comments
 (0)