@@ -192,12 +192,39 @@ export class BrowserOrejimeService extends OrejimeService {
192192 this . translateConfiguration ( ) ;
193193
194194 this . orejimeConfig . apps = this . filterConfigApps ( appsToHide ) ;
195- this . lazyOrejime . then ( ( { init } ) => {
195+
196+ this . applyUpdateSettingsCallbackToApps ( user ) ;
197+
198+ void this . lazyOrejime . then ( ( { init } ) => {
196199 this . orejimeInstance = init ( this . orejimeConfig ) ;
197200 } ) ;
198201 } ) ;
199202 }
200203
204+ /**
205+ * Applies a debounced callback to update user settings for all apps in the Orejime configuration.
206+ *
207+ * This method modifies the `callback` property of each app in the `orejimeConfig.apps` array.
208+ * It ensures that the `updateSettingsForUsers` method is called in a debounced manner whenever
209+ * a consent change occurs for any app. Additionally, it preserves and invokes the original
210+ * callback for each app if one is defined.
211+ *
212+ * @param {EPerson } user - The authenticated user whose settings are being updated.
213+ */
214+ applyUpdateSettingsCallbackToApps ( user : EPerson ) {
215+ const updateSettingsCallback = debounce ( ( ) => this . updateSettingsForUsers ( user ) , updateDebounce ) ;
216+
217+ this . orejimeConfig . apps . forEach ( ( app ) => {
218+ const originalCallback = app . callback ;
219+ app . callback = ( consent : boolean ) => {
220+ updateSettingsCallback ( ) ;
221+ if ( originalCallback ) {
222+ originalCallback ( consent ) ;
223+ }
224+ } ;
225+ } ) ;
226+ }
227+
201228 /**
202229 * Return saved preferences stored in the orejime cookie
203230 */
@@ -220,7 +247,6 @@ export class BrowserOrejimeService extends OrejimeService {
220247 * @param user The authenticated user
221248 */
222249 private initializeUser ( user : EPerson ) {
223- this . orejimeConfig . callback = debounce ( ( consent , app ) => this . updateSettingsForUsers ( user ) , updateDebounce ) ;
224250 this . orejimeConfig . cookieName = this . getStorageName ( user . uuid ) ;
225251
226252 const anonCookie = this . cookieService . get ( ANONYMOUS_STORAGE_NAME_OREJIME ) ;
@@ -387,7 +413,9 @@ export class BrowserOrejimeService extends OrejimeService {
387413 * @param user
388414 */
389415 updateSettingsForUsers ( user : EPerson ) {
390- this . setSettingsForUser ( user , this . cookieService . get ( this . getStorageName ( user . uuid ) ) ) ;
416+ if ( user ) {
417+ this . setSettingsForUser ( user , this . cookieService . get ( this . getStorageName ( user . uuid ) ) ) ;
418+ }
391419 }
392420
393421 /**
0 commit comments