Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/every-terms-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/shared': patch
---

Fix issue where `signUp.verifications.sendPhoneCode()` expected to be provided a `phoneNumber`.
48 changes: 20 additions & 28 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,26 @@ class SignUpFuture implements SignUpFutureResource {
});
}

async sendPhoneCode(params: SignUpFuturePhoneCodeSendParams): Promise<{ error: ClerkError | null }> {
const { channel = 'sms' } = params;
return runAsyncResourceTask(this.#resource, async () => {
await this.#resource.__internal_basePost({
body: { strategy: 'phone_code', channel },
action: 'prepare_verification',
});
});
}

async verifyPhoneCode(params: SignUpFuturePhoneCodeVerifyParams): Promise<{ error: ClerkError | null }> {
const { code } = params;
return runAsyncResourceTask(this.#resource, async () => {
await this.#resource.__internal_basePost({
body: { strategy: 'phone_code', code },
action: 'attempt_verification',
});
});
}

async sendEmailLink(params: SignUpFutureEmailLinkSendParams): Promise<{ error: ClerkError | null }> {
const { verificationUrl } = params;
return runAsyncResourceTask(this.#resource, async () => {
Expand Down Expand Up @@ -945,34 +965,6 @@ class SignUpFuture implements SignUpFutureResource {
});
}

async sendPhoneCode(params: SignUpFuturePhoneCodeSendParams): Promise<{ error: ClerkError | null }> {
const { phoneNumber, channel = 'sms' } = params;
return runAsyncResourceTask(this.#resource, async () => {
if (!this.#resource.id) {
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
await this.#resource.__internal_basePost({
path: this.#resource.pathRoot,
body: { phoneNumber, captchaToken, captchaWidgetType, captchaError },
});
}

await this.#resource.__internal_basePost({
body: { strategy: 'phone_code', channel },
action: 'prepare_verification',
});
});
}

async verifyPhoneCode(params: SignUpFuturePhoneCodeVerifyParams): Promise<{ error: ClerkError | null }> {
const { code } = params;
return runAsyncResourceTask(this.#resource, async () => {
await this.#resource.__internal_basePost({
body: { strategy: 'phone_code', code },
action: 'attempt_verification',
});
});
}

async sso(params: SignUpFutureSSOParams): Promise<{ error: ClerkError | null }> {
const {
strategy,
Expand Down
41 changes: 0 additions & 41 deletions packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,47 +160,6 @@ describe('SignUp', () => {
vi.unstubAllGlobals();
});

it('creates signup with phoneNumber when no existing signup', async () => {
const mockFetch = vi
.fn()
.mockResolvedValueOnce({
client: null,
response: { id: 'signup_123', status: 'missing_requirements' },
})
.mockResolvedValueOnce({
client: null,
response: { id: 'signup_123' },
});
BaseResource._fetch = mockFetch;

const signUp = new SignUp();
await signUp.__internal_future.verifications.sendPhoneCode({ phoneNumber: '+15551234567' });

// First call should create signup with phoneNumber
expect(mockFetch).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
method: 'POST',
path: '/client/sign_ups',
body: expect.objectContaining({
phoneNumber: '+15551234567',
}),
}),
);

// Second call should prepare verification
expect(mockFetch).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
method: 'POST',
path: '/client/sign_ups/signup_123/prepare_verification',
body: expect.objectContaining({
strategy: 'phone_code',
}),
}),
);
});

it('uses existing signup when already created', async () => {
const mockFetch = vi.fn().mockResolvedValue({
client: null,
Expand Down
6 changes: 0 additions & 6 deletions packages/shared/src/types/signUpFuture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ export type SignUpFuturePasswordParams = SignUpFutureAdditionalParams & {
);

export interface SignUpFuturePhoneCodeSendParams {
/**
* The user's phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164). Only supported if
* [phone number](https://clerk.com/docs/guides/configure/auth-strategies/sign-up-sign-in-options#phone) is enabled.
* Keep in mind that the phone number requires an extra verification process.
*/
phoneNumber?: string;
/**
* The mechanism to use to send the code to the provided phone number. Defaults to `'sms'`.
*/
Expand Down