From c338358bcb55849486424a07db463d460ab7d5d3 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Tue, 23 Apr 2024 14:52:54 +0300 Subject: [PATCH 1/2] fix(clerk-js): Use first-party cookies when running on Cypress --- .changeset/rotten-rats-carry.md | 5 +++++ packages/clerk-js/src/globals.d.ts | 1 + packages/clerk-js/src/utils/runtime.ts | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/rotten-rats-carry.md diff --git a/.changeset/rotten-rats-carry.md b/.changeset/rotten-rats-carry.md new file mode 100644 index 00000000000..3e15355ba88 --- /dev/null +++ b/.changeset/rotten-rats-carry.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Fix Cypress setting cookies as third-party diff --git a/packages/clerk-js/src/globals.d.ts b/packages/clerk-js/src/globals.d.ts index 26ef5a8a3c2..b6835d01737 100644 --- a/packages/clerk-js/src/globals.d.ts +++ b/packages/clerk-js/src/globals.d.ts @@ -6,6 +6,7 @@ declare global { interface Window { __unstable__onBeforeSetActive: () => Promise | void; __unstable__onAfterSetActive: () => Promise | void; + Cypress?: any; } } diff --git a/packages/clerk-js/src/utils/runtime.ts b/packages/clerk-js/src/utils/runtime.ts index fbd7d7a8d5d..1b5e5dfe863 100644 --- a/packages/clerk-js/src/utils/runtime.ts +++ b/packages/clerk-js/src/utils/runtime.ts @@ -11,7 +11,9 @@ export function usesHttps() { } export function inIframe() { - return inBrowser() && window.self !== window.top; + // checks if the current window is an iframe + // excludes the case where the current window runs in a Cypress test + return inBrowser() && window.self !== window.top && !window.Cypress; } export function inCrossOriginIframe() { From bd3f75e45d2a8341e23f12dcdb3c825af5da86f1 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Wed, 24 Apr 2024 15:52:39 +0300 Subject: [PATCH 2/2] fix(clerk-js): Create isCypress util --- packages/clerk-js/src/globals.d.ts | 1 - packages/clerk-js/src/utils/runtime.ts | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/clerk-js/src/globals.d.ts b/packages/clerk-js/src/globals.d.ts index b6835d01737..26ef5a8a3c2 100644 --- a/packages/clerk-js/src/globals.d.ts +++ b/packages/clerk-js/src/globals.d.ts @@ -6,7 +6,6 @@ declare global { interface Window { __unstable__onBeforeSetActive: () => Promise | void; __unstable__onAfterSetActive: () => Promise | void; - Cypress?: any; } } diff --git a/packages/clerk-js/src/utils/runtime.ts b/packages/clerk-js/src/utils/runtime.ts index 1b5e5dfe863..06a40433579 100644 --- a/packages/clerk-js/src/utils/runtime.ts +++ b/packages/clerk-js/src/utils/runtime.ts @@ -10,10 +10,14 @@ export function usesHttps() { return inBrowser() && window.location.protocol === 'https:'; } +function isCypress() { + return typeof window !== 'undefined' && typeof (window as any).Cypress !== 'undefined'; +} + export function inIframe() { // checks if the current window is an iframe // excludes the case where the current window runs in a Cypress test - return inBrowser() && window.self !== window.top && !window.Cypress; + return inBrowser() && window.self !== window.top && !isCypress(); } export function inCrossOriginIframe() {