Skip to content

Commit 9d00c7c

Browse files
committed
fix(clerk-js): update session cookie domain assertions in integration tests
Update integration tests to expect session cookies on eTLD+1 (with leading dot) instead of the exact hostname, matching the new behavior where session cookies are set with an explicit domain attribute. Add changeset.
1 parent 18dc0cd commit 9d00c7c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Set session cookies on the eTLD+1 domain to align with FAPI and prevent duplicate cookies across domain scopes that cause 401s after inactivity

integration/tests/sessions/root-subdomain-prod-instances.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ test.describe('root and subdomain production apps @sessions', () => {
108108
// Check that the cookies are set as expected
109109
const tab0Cookies = await u[0].page.cookies();
110110
expect(tab0Cookies.get('__session')).toBeDefined();
111-
expect(tab0Cookies.get('__session').domain).toEqual(hosts[0].split(':')[0]);
111+
// The session cookie should be set on etld+1 (with leading dot from the domain attribute)
112+
expect(tab0Cookies.get('__session').domain).toEqual('.' + hosts[0].split(':')[0]);
112113
expect(tab0Cookies.get('__session').value).toEqual(tab0Cookies.get('__session_*').value);
113114
expect(tab0Cookies.get('__session_*').name.split('__session_')[1].length).toEqual(8);
114115

@@ -119,6 +120,9 @@ test.describe('root and subdomain production apps @sessions', () => {
119120
expect(tab0Cookies.get('__client_uat').domain).toEqual(tab0Cookies.get('__client_uat_*').domain);
120121
expect(tab0Cookies.get('__client_uat_*').name.split('__client_uat_')[1].length).toEqual(8);
121122

123+
// The session cookie domain should match the client_uat cookie domain (both on etld+1)
124+
expect(tab0Cookies.get('__session').domain).toEqual(tab0Cookies.get('__client_uat').domain);
125+
122126
await u[1].page.goto(`https://${hosts[1]}`);
123127
// user should be signed in already
124128
await u[1].po.expect.toBeSignedIn();
@@ -140,10 +144,10 @@ test.describe('root and subdomain production apps @sessions', () => {
140144
expect(tab0Cookies.get('__client_uat_*').domain).toEqual(tab1Cookies.get('__client_uat_*').domain);
141145
// There should be 1 base client_uat cookie and 1 suffixed variants
142146
expect(tab0Cookies.raw().filter(c => c.name.startsWith('__client_uat')).length).toEqual(2);
143-
// the session cookie should be set on the domain of the app
144-
// so, it can be accessed by the host server
145-
expect(tab1Cookies.get('__session').domain).toEqual(hosts[1].split(':')[0]);
146-
expect(tab1Cookies.get('__session').domain).not.toEqual(tab0Cookies.get('__session').domain);
147+
// the session cookie should be set on etld+1
148+
// so, it can be shared between all subdomains for the same instance
149+
expect(tab1Cookies.get('__session').domain).toEqual('.' + hosts[0].split(':')[0]);
150+
expect(tab1Cookies.get('__session').domain).toEqual(tab0Cookies.get('__session').domain);
147151
});
148152

149153
test('signing out from the sub domains signs out the user from the root domain as well', async ({ context }) => {
@@ -250,7 +254,8 @@ test.describe('root and subdomain production apps @sessions', () => {
250254
expect(tab0Cookies.get('__client').httpOnly).toBeTruthy();
251255

252256
expect(tab0Cookies.get('__session')).toBeDefined();
253-
expect(tab0Cookies.get('__session').domain).toEqual(hosts[0].split(':')[0]);
257+
// The session cookie should be set on etld+1 (with leading dot from the domain attribute)
258+
expect(tab0Cookies.get('__session').domain).toEqual('.' + hosts[0].split(':')[0]);
254259

255260
// ensure that only 2 client_uat cookies (base and suffixed variant) are visible here
256261
expect([...tab0Cookies.values()].filter(c => c.name.startsWith('__client_uat')).length).toEqual(2);
@@ -277,7 +282,8 @@ test.describe('root and subdomain production apps @sessions', () => {
277282
expect(tab1Cookies.get('__client').domain).toBe(`.clerk.${hosts[1].split(':')[0]}`);
278283

279284
expect(tab1Cookies.get('__session')).toBeDefined();
280-
expect(tab1Cookies.get('__session').domain).toEqual(hosts[1].split(':')[0]);
285+
// The session cookie should be set on etld+1 (with leading dot from the domain attribute)
286+
expect(tab1Cookies.get('__session').domain).toEqual('.' + hosts[0].split(':')[0]);
281287

282288
// ensure that all client_uat cookies are still set on the root domain
283289
expect(tab1Cookies.get('__client_uat_*').domain).toEqual('.' + hosts[0].split(':')[0]);

0 commit comments

Comments
 (0)