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
5 changes: 5 additions & 0 deletions .changeset/wise-bottles-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Post captcha tokens to /client/verify instead of PATCH /client
8 changes: 4 additions & 4 deletions packages/clerk-js/src/core/resources/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export abstract class BaseResource {
return this._baseMutate<J>({ ...params, method: 'POST' });
}

protected async _basePostBypass<J extends ClerkResourceJSON>(params: BaseMutateParams = {}): Promise<this> {
return this._baseMutateBypass<J>({ ...params, method: 'POST' });
}

protected async _basePut<J extends ClerkResourceJSON | null>(params: BaseMutateParams = {}): Promise<this> {
return this._baseMutate<J>({ ...params, method: 'PUT' });
}
Expand All @@ -203,10 +207,6 @@ export abstract class BaseResource {
return this._baseMutate<J>({ ...params, method: 'PATCH' });
}

protected async _basePatchBypass<J extends ClerkResourceJSON>(params: BaseMutateParams = {}): Promise<this> {
return this._baseMutateBypass<J>({ ...params, method: 'PATCH' });
}

protected async _baseDelete<J extends ClerkResourceJSON | null>(params: BaseMutateParams = {}): Promise<void> {
await this._baseMutate<J>({ ...params, method: 'DELETE' });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Client extends BaseResource implements ClientResource {
}

public sendCaptchaToken(params: unknown): Promise<ClientResource> {
return this._basePatchBypass({ body: params });
return this._basePostBypass({ body: params, path: this.path() + '/verify' });
}

fromJSON(data: ClientJSON | ClientJSONSnapshot | null): this {
Expand Down
30 changes: 30 additions & 0 deletions packages/clerk-js/src/core/resources/__tests__/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ import { createSession, createSignIn, createSignUp, createUser } from '../../tes
import { BaseResource, Client } from '../internal';

describe('Client Singleton', () => {
it('sends captcha token', async () => {
const user = createUser({ first_name: 'John', last_name: 'Doe', id: 'user_1' });
const session = createSession({ id: 'session_1' }, user);
const clientObjectJSON: ClientJSON = {
object: 'client',
id: 'test_id',
status: 'active',
last_active_session_id: 'test_session_id',
sign_in: createSignIn({ id: 'test_sign_in_id' }, user),
sign_up: createSignUp({ id: 'test_sign_up_id' }), // This is only for testing purposes, this will never happen
sessions: [session],
created_at: jest.now() - 1000,
updated_at: jest.now(),
} as any;

// @ts-expect-error This is a private method that we are mocking
BaseResource._baseFetch = jest.fn();

const client = Client.getOrCreateInstance().fromJSON(clientObjectJSON);
await client.sendCaptchaToken({ captcha_token: 'test_captcha_token' });
// @ts-expect-error This is a private method that we are mocking
expect(BaseResource._baseFetch).toHaveBeenCalledWith({
method: 'POST',
path: `/client/verify`,
body: {
captcha_token: 'test_captcha_token',
},
});
});

it('destroy', async () => {
const user = createUser({ first_name: 'John', last_name: 'Doe', id: 'user_1' });
const session = createSession({ id: 'session_1' }, user);
Expand Down
Loading