Skip to content

Commit a05d130

Browse files
authored
fix(clerk-js,shared): Do not expect phoneNumber for sendPhoneCode (#7869)
1 parent 223a5fc commit a05d130

4 files changed

Lines changed: 26 additions & 75 deletions

File tree

.changeset/every-terms-care.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/shared': patch
4+
---
5+
6+
Fix issue where `signUp.verifications.sendPhoneCode()` expected to be provided a `phoneNumber`.

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,26 @@ class SignUpFuture implements SignUpFutureResource {
905905
});
906906
}
907907

908+
async sendPhoneCode(params: SignUpFuturePhoneCodeSendParams): Promise<{ error: ClerkError | null }> {
909+
const { channel = 'sms' } = params;
910+
return runAsyncResourceTask(this.#resource, async () => {
911+
await this.#resource.__internal_basePost({
912+
body: { strategy: 'phone_code', channel },
913+
action: 'prepare_verification',
914+
});
915+
});
916+
}
917+
918+
async verifyPhoneCode(params: SignUpFuturePhoneCodeVerifyParams): Promise<{ error: ClerkError | null }> {
919+
const { code } = params;
920+
return runAsyncResourceTask(this.#resource, async () => {
921+
await this.#resource.__internal_basePost({
922+
body: { strategy: 'phone_code', code },
923+
action: 'attempt_verification',
924+
});
925+
});
926+
}
927+
908928
async sendEmailLink(params: SignUpFutureEmailLinkSendParams): Promise<{ error: ClerkError | null }> {
909929
const { verificationUrl } = params;
910930
return runAsyncResourceTask(this.#resource, async () => {
@@ -945,34 +965,6 @@ class SignUpFuture implements SignUpFutureResource {
945965
});
946966
}
947967

948-
async sendPhoneCode(params: SignUpFuturePhoneCodeSendParams): Promise<{ error: ClerkError | null }> {
949-
const { phoneNumber, channel = 'sms' } = params;
950-
return runAsyncResourceTask(this.#resource, async () => {
951-
if (!this.#resource.id) {
952-
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
953-
await this.#resource.__internal_basePost({
954-
path: this.#resource.pathRoot,
955-
body: { phoneNumber, captchaToken, captchaWidgetType, captchaError },
956-
});
957-
}
958-
959-
await this.#resource.__internal_basePost({
960-
body: { strategy: 'phone_code', channel },
961-
action: 'prepare_verification',
962-
});
963-
});
964-
}
965-
966-
async verifyPhoneCode(params: SignUpFuturePhoneCodeVerifyParams): Promise<{ error: ClerkError | null }> {
967-
const { code } = params;
968-
return runAsyncResourceTask(this.#resource, async () => {
969-
await this.#resource.__internal_basePost({
970-
body: { strategy: 'phone_code', code },
971-
action: 'attempt_verification',
972-
});
973-
});
974-
}
975-
976968
async sso(params: SignUpFutureSSOParams): Promise<{ error: ClerkError | null }> {
977969
const {
978970
strategy,

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -160,47 +160,6 @@ describe('SignUp', () => {
160160
vi.unstubAllGlobals();
161161
});
162162

163-
it('creates signup with phoneNumber when no existing signup', async () => {
164-
const mockFetch = vi
165-
.fn()
166-
.mockResolvedValueOnce({
167-
client: null,
168-
response: { id: 'signup_123', status: 'missing_requirements' },
169-
})
170-
.mockResolvedValueOnce({
171-
client: null,
172-
response: { id: 'signup_123' },
173-
});
174-
BaseResource._fetch = mockFetch;
175-
176-
const signUp = new SignUp();
177-
await signUp.__internal_future.verifications.sendPhoneCode({ phoneNumber: '+15551234567' });
178-
179-
// First call should create signup with phoneNumber
180-
expect(mockFetch).toHaveBeenNthCalledWith(
181-
1,
182-
expect.objectContaining({
183-
method: 'POST',
184-
path: '/client/sign_ups',
185-
body: expect.objectContaining({
186-
phoneNumber: '+15551234567',
187-
}),
188-
}),
189-
);
190-
191-
// Second call should prepare verification
192-
expect(mockFetch).toHaveBeenNthCalledWith(
193-
2,
194-
expect.objectContaining({
195-
method: 'POST',
196-
path: '/client/sign_ups/signup_123/prepare_verification',
197-
body: expect.objectContaining({
198-
strategy: 'phone_code',
199-
}),
200-
}),
201-
);
202-
});
203-
204163
it('uses existing signup when already created', async () => {
205164
const mockFetch = vi.fn().mockResolvedValue({
206165
client: null,

packages/shared/src/types/signUpFuture.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ export type SignUpFuturePasswordParams = SignUpFutureAdditionalParams & {
178178
);
179179

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

0 commit comments

Comments
 (0)