From c8102b9ea0a9387a4dcc13c81e73e65844ca4c86 Mon Sep 17 00:00:00 2001 From: Johannes Doberer Date: Thu, 10 Oct 2024 12:08:05 +0200 Subject: [PATCH] Disable tpc via client (#3983) --- client/luigi-client.d.ts | 8 ++++++-- client/src/lifecycleManager.js | 7 +++++-- client/src/luigi-client.js | 5 ++--- docs/luigi-client-api.md | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/client/luigi-client.d.ts b/client/luigi-client.d.ts index b40368e043..0215750fc3 100644 --- a/client/luigi-client.d.ts +++ b/client/luigi-client.d.ts @@ -594,10 +594,14 @@ export declare interface StorageManager { /** * Registers a listener called with the context object and the Luigi Core domain as soon as Luigi is instantiated. Defer your application bootstrap if you depend on authentication data coming from Luigi. * @param {Lifecycle~initListenerCallback} initFn the function that is called once Luigi is initialized, receives current context and origin as parameters + * @param {boolean} disableTpcCheck if set to `true` third party cookie check will be disabled via LuigiClient. * @memberof Lifecycle */ -export function addInitListener(initFn: (context: Context, origin?: string) => void): number; -export type addInitListener = (initFn: (context: Context, origin?: string) => void) => number; +export function addInitListener(initFn: (context: Context, origin?: string) => void, disableTpcCheck?: boolean): number; +export type addInitListener = ( + initFn: (context: Context, origin?: string) => void, + disableTpcCheck?: boolean +) => number; /** * Callback of the addInitListener diff --git a/client/src/lifecycleManager.js b/client/src/lifecycleManager.js index 5b9f2fab5d..f186c1b6d1 100644 --- a/client/src/lifecycleManager.js +++ b/client/src/lifecycleManager.js @@ -9,6 +9,7 @@ class LifecycleManager extends LuigiClientBase { /** @private */ constructor() { super(); + this.disableTpcCheck = false; this.luigiInitialized = false; this.defaultContextKeys = ['context', 'internal', 'nodeParams', 'pathParams', 'searchParams']; this.setCurrentContext( @@ -139,7 +140,7 @@ class LifecycleManager extends LuigiClientBase { } _tpcCheck() { - if (this.currentContext?.internal?.thirdPartyCookieCheck?.disabled) { + if (this.currentContext?.internal?.thirdPartyCookieCheck?.disabled || this.disableTpcCheck) { return; } let tpc = 'enabled'; @@ -226,11 +227,13 @@ class LifecycleManager extends LuigiClientBase { /** * Registers a listener called with the context object and the Luigi Core domain as soon as Luigi is instantiated. Defer your application bootstrap if you depend on authentication data coming from Luigi. * @param {Lifecycle~initListenerCallback} initFn the function that is called once Luigi is initialized, receives current context and origin as parameters + * @param {boolean} disableTpcCheck if set to `true` third party cookie check will be disabled via LuigiClient. * @memberof Lifecycle * @example * const initListenerId = LuigiClient.addInitListener((context) => storeContextToMF(context)) */ - addInitListener(initFn) { + addInitListener(initFn, disableTpcCheck) { + this.disableTpcCheck = disableTpcCheck; const id = helpers.getRandomId(); this._onInitFns[id] = initFn; if (this.luigiInitialized && helpers.isFunction(initFn)) { diff --git a/client/src/luigi-client.js b/client/src/luigi-client.js index 9e6be7adbf..e275a5d0d3 100644 --- a/client/src/luigi-client.js +++ b/client/src/luigi-client.js @@ -26,8 +26,8 @@ class LuigiClient { } } - addInitListener(initFn) { - return lifecycleManager.addInitListener(initFn); + addInitListener(initFn, disableTpcCheck) { + return lifecycleManager.addInitListener(initFn, disableTpcCheck); } removeInitListener(id) { return lifecycleManager.removeInitListener(id); @@ -105,7 +105,6 @@ class LuigiClient { return lifecycleManager.setViewGroupData(value); } - /** * @private */ diff --git a/docs/luigi-client-api.md b/docs/luigi-client-api.md index a13e9351bb..bfd865e856 100644 --- a/docs/luigi-client-api.md +++ b/docs/luigi-client-api.md @@ -136,6 +136,7 @@ Registers a listener called with the context object and the Luigi Core domain as ##### Parameters * `initFn` **[Lifecycle~initListenerCallback](#lifecycleinitlistenercallback)** the function that is called once Luigi is initialized, receives current context and origin as parameters +* `disableTpcCheck` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if set to `true` third party cookie check will be disabled via LuigiClient. ##### Examples