Skip to content

Commit 5f58a22

Browse files
authored
refactor(clerk-js,nextjs,clerk-react,shared,types): Remove hashing and (#2367)
third-party cookie based session syncing for development instances.
1 parent 435ab50 commit 5f58a22

14 files changed

+161
-272
lines changed

.changeset/famous-penguins-bow.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/types': major
3+
---
4+
5+
- Remove `BuildUrlWithAuthParams` type
6+
- `AuthConfigResource` no longer has a `urlBasedSessionSyncing` property
7+
- `buildUrlWithAuth` no longer accepts an `options` argument of `BuildUrlWithAuthParams`.

.changeset/modern-buses-sort.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/chrome-extension': major
3+
'@clerk/clerk-js': major
4+
'@clerk/nextjs': major
5+
'@clerk/shared': major
6+
'@clerk/clerk-react': major
7+
'@clerk/types': major
8+
---
9+
10+
Remove hashing and third-party cookie functionality related to development instance session syncing in favor of URL-based session syncing with query parameters.

.changeset/modern-mayflies-sort.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': major
3+
'@clerk/clerk-react': major
4+
---
5+
6+
- `buildUrlWithAuth` no longer accepts an `options` argument.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { Clerk } from './clerk';
2-
import type { AuthConfig, DisplayConfig } from './resources/internal';
2+
import type { DevBrowser } from './devBrowser';
3+
import type { DisplayConfig } from './resources/internal';
34
import { Client, Environment } from './resources/internal';
45

56
const mockClientFetch = jest.fn();
67
const mockEnvironmentFetch = jest.fn();
7-
const mockUsesUrlBasedSessionSync = jest.fn();
88

99
jest.mock('./resources/Client');
1010
jest.mock('./resources/Environment');
1111

1212
// Because Jest, don't ask me why...
1313
jest.mock('./devBrowser', () => ({
14-
createDevBrowser: () => ({
14+
createDevBrowser: (): DevBrowser => ({
1515
clear: jest.fn(),
1616
setup: jest.fn(),
1717
getDevBrowserJWT: jest.fn(() => 'deadbeef'),
@@ -57,7 +57,9 @@ const developmentPublishableKey = 'pk_test_Y2xlcmsuYWJjZWYuMTIzNDUuZGV2LmxjbGNsZ
5757
const productionPublishableKey = 'pk_live_Y2xlcmsuYWJjZWYuMTIzNDUucHJvZC5sY2xjbGVyay5jb20k';
5858

5959
describe('Clerk singleton - Redirects', () => {
60-
let mockNavigate = jest.fn();
60+
const mockNavigate = jest.fn((to: string) => Promise.resolve(to));
61+
const mockedLoadOptions = { routerPush: mockNavigate, routerReplace: mockNavigate };
62+
6163
let mockWindowLocation;
6264
let mockHref: jest.Mock;
6365

@@ -90,10 +92,10 @@ describe('Clerk singleton - Redirects', () => {
9092
activeSessions: [],
9193
}),
9294
);
93-
94-
mockNavigate = jest.fn((to: string) => Promise.resolve(to));
9595
});
9696

97+
afterEach(() => mockNavigate.mockReset());
98+
9799
describe('.redirectTo(SignUp|SignIn|UserProfile|AfterSignIn|AfterSignUp|CreateOrganization|OrganizationProfile)', () => {
98100
let clerkForProductionInstance: Clerk;
99101
let clerkForDevelopmentInstance: Clerk;
@@ -102,25 +104,18 @@ describe('Clerk singleton - Redirects', () => {
102104
beforeEach(async () => {
103105
mockEnvironmentFetch.mockReturnValue(
104106
Promise.resolve({
105-
authConfig: { urlBasedSessionSyncing: true } as AuthConfig,
106107
userSettings: mockUserSettings,
107108
displayConfig: mockDisplayConfigWithSameOrigin,
108109
isProduction: () => false,
109110
isDevelopmentOrStaging: () => true,
110111
}),
111112
);
112113

113-
mockUsesUrlBasedSessionSync.mockReturnValue(true);
114-
115114
clerkForProductionInstance = new Clerk(productionPublishableKey);
116-
await clerkForProductionInstance.load({
117-
routerPush: mockNavigate,
118-
});
119-
120115
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
121-
await clerkForDevelopmentInstance.load({
122-
routerPush: mockNavigate,
123-
});
116+
117+
await clerkForProductionInstance.load(mockedLoadOptions);
118+
await clerkForDevelopmentInstance.load(mockedLoadOptions);
124119
});
125120

126121
afterEach(() => {
@@ -129,57 +124,57 @@ describe('Clerk singleton - Redirects', () => {
129124

130125
it('redirects to signInUrl', async () => {
131126
await clerkForProductionInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
132-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
133-
134127
await clerkForDevelopmentInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
128+
129+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
135130
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
136131
});
137132

138133
it('redirects to signUpUrl', async () => {
139134
await clerkForProductionInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
140-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
141-
142135
await clerkForDevelopmentInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
136+
137+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
143138
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
144139
});
145140

146141
it('redirects to userProfileUrl', async () => {
147142
await clerkForProductionInstance.redirectToUserProfile();
148-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/user-profile');
149-
150143
await clerkForDevelopmentInstance.redirectToUserProfile();
144+
145+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/user-profile');
151146
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/user-profile');
152147
});
153148

154149
it('redirects to afterSignUp', async () => {
155150
await clerkForProductionInstance.redirectToAfterSignUp();
156-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/');
157-
158151
await clerkForDevelopmentInstance.redirectToAfterSignUp();
152+
153+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/');
159154
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/');
160155
});
161156

162157
it('redirects to afterSignIn', async () => {
163158
await clerkForProductionInstance.redirectToAfterSignIn();
164-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/');
165-
166159
await clerkForDevelopmentInstance.redirectToAfterSignIn();
160+
161+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/');
167162
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/');
168163
});
169164

170165
it('redirects to create organization', async () => {
171166
await clerkForProductionInstance.redirectToCreateOrganization();
172-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/create-organization');
173-
174167
await clerkForDevelopmentInstance.redirectToCreateOrganization();
168+
169+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/create-organization');
175170
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/create-organization');
176171
});
177172

178173
it('redirects to organization profile', async () => {
179174
await clerkForProductionInstance.redirectToOrganizationProfile();
180-
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/organization-profile');
181-
182175
await clerkForDevelopmentInstance.redirectToOrganizationProfile();
176+
177+
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/organization-profile');
183178
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/organization-profile');
184179
});
185180
});
@@ -188,87 +183,71 @@ describe('Clerk singleton - Redirects', () => {
188183
beforeEach(async () => {
189184
mockEnvironmentFetch.mockReturnValue(
190185
Promise.resolve({
191-
authConfig: { urlBasedSessionSyncing: true } as AuthConfig,
192186
userSettings: mockUserSettings,
193187
displayConfig: mockDisplayConfigWithDifferentOrigin,
194188
isProduction: () => false,
195189
isDevelopmentOrStaging: () => true,
196190
}),
197191
);
198192

199-
mockUsesUrlBasedSessionSync.mockReturnValue(true);
200-
201193
clerkForProductionInstance = new Clerk(productionPublishableKey);
202-
await clerkForProductionInstance.load({
203-
routerPush: mockNavigate,
204-
});
205-
206194
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
207-
await clerkForDevelopmentInstance.load({
208-
routerPush: mockNavigate,
209-
});
195+
196+
await clerkForProductionInstance.load(mockedLoadOptions);
197+
await clerkForDevelopmentInstance.load(mockedLoadOptions);
210198
});
211199

212200
afterEach(() => {
213201
mockEnvironmentFetch.mockRestore();
214202
});
215203

204+
const host = 'http://another-test.host';
205+
216206
it('redirects to signInUrl', async () => {
217207
await clerkForProductionInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
218-
expect(mockHref).toHaveBeenNthCalledWith(
219-
1,
220-
'http://another-test.host/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F',
221-
);
222-
223208
await clerkForDevelopmentInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
209+
210+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F`);
211+
224212
expect(mockHref).toHaveBeenNthCalledWith(
225213
2,
226-
'http://another-test.host/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
214+
`${host}/sign-in?__clerk_db_jwt=deadbeef#/?redirect_url=https%3A%2F%2Fwww.example.com%2F`,
227215
);
228216
});
229217

230218
it('redirects to signUpUrl', async () => {
231219
await clerkForProductionInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
232-
expect(mockHref).toHaveBeenNthCalledWith(
233-
1,
234-
'http://another-test.host/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F',
235-
);
236-
237220
await clerkForDevelopmentInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
221+
222+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F`);
238223
expect(mockHref).toHaveBeenNthCalledWith(
239224
2,
240-
'http://another-test.host/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
225+
`${host}/sign-up?__clerk_db_jwt=deadbeef#/?redirect_url=https%3A%2F%2Fwww.example.com%2F`,
241226
);
242227
});
243228

244229
it('redirects to userProfileUrl', async () => {
245230
await clerkForProductionInstance.redirectToUserProfile();
246-
expect(mockHref).toHaveBeenNthCalledWith(1, 'http://another-test.host/user-profile');
247-
248231
await clerkForDevelopmentInstance.redirectToUserProfile();
249-
expect(mockHref).toHaveBeenNthCalledWith(2, 'http://another-test.host/user-profile#__clerk_db_jwt[deadbeef]');
232+
233+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/user-profile`);
234+
expect(mockHref).toHaveBeenNthCalledWith(2, `${host}/user-profile?__clerk_db_jwt=deadbeef`);
250235
});
251236

252237
it('redirects to create organization', async () => {
253238
await clerkForProductionInstance.redirectToCreateOrganization();
254-
expect(mockHref).toHaveBeenNthCalledWith(1, 'http://another-test.host/create-organization');
255-
256239
await clerkForDevelopmentInstance.redirectToCreateOrganization();
257-
expect(mockHref).toHaveBeenNthCalledWith(
258-
2,
259-
'http://another-test.host/create-organization#__clerk_db_jwt[deadbeef]',
260-
);
240+
241+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/create-organization`);
242+
expect(mockHref).toHaveBeenNthCalledWith(2, `${host}/create-organization?__clerk_db_jwt=deadbeef`);
261243
});
262244

263245
it('redirects to organization profile', async () => {
264246
await clerkForProductionInstance.redirectToOrganizationProfile();
265-
expect(mockHref).toHaveBeenNthCalledWith(1, 'http://another-test.host/organization-profile');
266-
267247
await clerkForDevelopmentInstance.redirectToOrganizationProfile();
268-
expect(mockHref).toHaveBeenNthCalledWith(
269-
2,
270-
'http://another-test.host/organization-profile#__clerk_db_jwt[deadbeef]',
271-
);
248+
249+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/organization-profile`);
250+
expect(mockHref).toHaveBeenNthCalledWith(2, `${host}/organization-profile?__clerk_db_jwt=deadbeef`);
272251
});
273252
});
274253
});
@@ -278,10 +257,8 @@ describe('Clerk singleton - Redirects', () => {
278257
let clerkForDevelopmentInstance: Clerk;
279258

280259
beforeEach(async () => {
281-
mockUsesUrlBasedSessionSync.mockReturnValue(true);
282260
mockEnvironmentFetch.mockReturnValue(
283261
Promise.resolve({
284-
authConfig: { urlBasedSessionSyncing: true } as AuthConfig,
285262
userSettings: mockUserSettings,
286263
displayConfig: mockDisplayConfigWithDifferentOrigin,
287264
isProduction: () => false,
@@ -290,22 +267,20 @@ describe('Clerk singleton - Redirects', () => {
290267
);
291268

292269
clerkForProductionInstance = new Clerk(productionPublishableKey);
293-
await clerkForProductionInstance.load({
294-
routerPush: mockNavigate,
295-
});
296-
297270
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);
298-
await clerkForDevelopmentInstance.load({
299-
routerPush: mockNavigate,
300-
});
271+
272+
await clerkForProductionInstance.load(mockedLoadOptions);
273+
await clerkForDevelopmentInstance.load(mockedLoadOptions);
301274
});
302275

276+
const host = 'https://app.example.com';
277+
303278
it('redirects to the provided url with __clerk_db_jwt in the url', async () => {
304-
await clerkForProductionInstance.redirectWithAuth('https://app.example.com');
305-
expect(mockHref).toHaveBeenNthCalledWith(1, 'https://app.example.com/');
279+
await clerkForProductionInstance.redirectWithAuth(host);
280+
await clerkForDevelopmentInstance.redirectWithAuth(host);
306281

307-
await clerkForDevelopmentInstance.redirectWithAuth('https://app.example.com');
308-
expect(mockHref).toHaveBeenNthCalledWith(2, 'https://app.example.com/#__clerk_db_jwt[deadbeef]');
282+
expect(mockHref).toHaveBeenNthCalledWith(1, `${host}/`);
283+
expect(mockHref).toHaveBeenNthCalledWith(2, `${host}/?__clerk_db_jwt=deadbeef`);
309284
});
310285
});
311286
});

0 commit comments

Comments
 (0)