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/signup-future-resource-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fix Future `signUp.update()` and `signUp.sso()` to patch the active sign-up resource URL when continuing an existing sign-up.
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ class SignUpFuture implements SignUpFutureResource {
unsafeMetadata: params.unsafeMetadata ? normalizeUnsafeMetadata(params.unsafeMetadata) : undefined,
};

await this.#resource.__internal_basePatch({ path: this.#resource.pathRoot, body });
await this.#resource.__internal_basePatch({ body });
});
}

Expand Down Expand Up @@ -1039,7 +1039,7 @@ class SignUpFuture implements SignUpFutureResource {
captchaError,
};
if (this.#resource.id) {
return this.#resource.__internal_basePatch({ path: this.#resource.pathRoot, body });
return this.#resource.__internal_basePatch({ body });
}
return this.#resource.__internal_basePost({ path: this.#resource.pathRoot, body });
};
Expand Down
137 changes: 137 additions & 0 deletions packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,35 @@ describe('SignUp', () => {
});
});

describe('update', () => {
afterEach(() => {
vi.clearAllMocks();
vi.unstubAllGlobals();
SignUp.clerk = {} as any;
});

it('patches the active sign up resource', async () => {
const mockFetch = vi.fn().mockResolvedValue({
client: null,
response: { id: 'signup_123', first_name: 'Ada' },
});
BaseResource._fetch = mockFetch;

const signUp = new SignUp({ id: 'signup_123' } as any);
await signUp.__internal_future.update({ firstName: 'Ada' });

expect(mockFetch).toHaveBeenCalledWith(
expect.objectContaining({
method: 'PATCH',
path: '/client/sign_ups/signup_123',
body: expect.objectContaining({
firstName: 'Ada',
}),
}),
);
});
});

describe('sendPhoneCode', () => {
afterEach(() => {
vi.clearAllMocks();
Expand Down Expand Up @@ -669,6 +698,114 @@ describe('SignUp', () => {
);
});

it('continues an existing sign up via the resource URL', async () => {
vi.stubGlobal('window', { location: { origin: 'https://example.com' } });

const mockBuildUrlWithAuth = vi.fn().mockReturnValue('https://example.com/sso-callback');
SignUp.clerk = {
buildUrlWithAuth: mockBuildUrlWithAuth,
__internal_environment: {
displayConfig: {
captchaOauthBypass: [],
},
},
} as any;

const mockFetch = vi.fn().mockResolvedValue({
client: null,
response: {
id: 'signup_123',
verifications: {
external_account: {
status: 'complete',
},
},
},
});
BaseResource._fetch = mockFetch;

const signUp = new SignUp({ id: 'signup_123' } as any);
await signUp.__internal_future.sso({
strategy: 'oauth_google',
redirectUrl: '/complete',
redirectCallbackUrl: '/sso-callback',
});

expect(mockFetch).toHaveBeenCalledWith(
expect.objectContaining({
method: 'PATCH',
path: '/client/sign_ups/signup_123',
body: expect.objectContaining({
strategy: 'oauth_google',
redirectUrl: 'https://example.com/sso-callback',
actionCompleteRedirectUrl: 'https://example.com/complete',
}),
}),
);
});

it('continues a ticket sign up with sso via the resource URL', async () => {
vi.stubGlobal('window', { location: { origin: 'https://example.com' } });

const mockBuildUrlWithAuth = vi.fn().mockReturnValue('https://example.com/sso-callback');
SignUp.clerk = {
buildUrlWithAuth: mockBuildUrlWithAuth,
__internal_environment: {
displayConfig: {
captchaOauthBypass: [],
},
},
} as any;

const mockFetch = vi
.fn()
.mockResolvedValueOnce({
client: null,
response: { id: 'signup_123' },
})
.mockResolvedValueOnce({
client: null,
response: {
id: 'signup_123',
verifications: {
external_account: {
status: 'complete',
},
},
},
});
BaseResource._fetch = mockFetch;

const signUp = new SignUp();
await signUp.__internal_future.ticket({ ticket: 'provided_ticket' });
await signUp.__internal_future.sso({
strategy: 'oauth_google',
redirectUrl: '/complete',
redirectCallbackUrl: '/sso-callback',
});

expect(mockFetch).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
method: 'POST',
path: '/client/sign_ups',
body: expect.objectContaining({
ticket: 'provided_ticket',
}),
}),
);
expect(mockFetch).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
method: 'PATCH',
path: '/client/sign_ups/signup_123',
body: expect.objectContaining({
strategy: 'oauth_google',
}),
}),
);
});

it('uses popup when provided', async () => {
vi.stubGlobal('window', { location: { origin: 'https://example.com' } });

Expand Down
Loading