Skip to content

Commit

Permalink
Disable tpc via client (#3983)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Oct 10, 2024
1 parent 96bf22c commit c8102b9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions client/luigi-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions client/src/lifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 2 additions & 3 deletions client/src/luigi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -105,7 +105,6 @@ class LuigiClient {
return lifecycleManager.setViewGroupData(value);
}


/**
* @private
*/
Expand Down
1 change: 1 addition & 0 deletions docs/luigi-client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8102b9

Please sign in to comment.