Skip to content

Commit 38cfe62

Browse files
Fixed automated consent being overridden by existing cookie consent (#7281)
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent b6b1b18 commit 38cfe62

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

clients/fides-js/src/lib/automated-consent.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,22 @@ export const calculateAutomatedConsent = (
143143
let consentMethod: ConsentMethod = ConsentMethod.SCRIPT;
144144
// Determine consent method based on priority (highest to lowest)
145145
if (migratedConsentApplied && migrationMethod) {
146-
fidesDebugger("Calculated automated consent from migrated provider");
146+
fidesDebugger(
147+
"Calculated automated consent from migrated provider",
148+
noticeConsentToSave,
149+
);
147150
consentMethod = migrationMethod;
148151
} else if (noticeConsentApplied) {
149-
fidesDebugger("Calculated automated consent from Notice Consent string");
152+
fidesDebugger(
153+
"Calculated automated consent from Notice Consent string",
154+
noticeConsentToSave,
155+
);
150156
consentMethod = ConsentMethod.SCRIPT;
151157
} else if (gpcApplied) {
152-
fidesDebugger("Calculated automated consent from GPC");
158+
fidesDebugger(
159+
"Calculated automated consent from GPC",
160+
noticeConsentToSave,
161+
);
153162
consentMethod = ConsentMethod.GPC;
154163
}
155164

clients/fides-js/src/lib/initialize.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ export const initialize = async ({
298298
);
299299

300300
/**
301-
* Apply calculated automated consent to experience defaults BEFORE updating cookie
301+
/**
302+
* Apply calculated automated consent to experience defaults and save to browser cookie
302303
*/
303304
if (automatedApplied && fides.experience.privacy_notices) {
304305
// Update experience privacy_notices with calculated automated consent
@@ -319,6 +320,22 @@ export const initialize = async ({
319320
},
320321
);
321322
fidesDebugger("Applied automated consent to experience defaults");
323+
324+
// save the cookie to the browser prior to updating the experience
325+
Object.assign(fides.cookie.fides_meta, {
326+
consentMethod: automatedMethod,
327+
});
328+
// eslint-disable-next-line no-param-reassign
329+
fides.cookie = {
330+
...fides.cookie,
331+
consent: automatedNoticeConsent,
332+
};
333+
await saveFidesCookie(fides.cookie, options);
334+
335+
fidesDebugger(
336+
"Saved automated consent to browser cookie",
337+
fides.cookie,
338+
);
322339
}
323340

324341
/**
@@ -376,20 +393,6 @@ export const initialize = async ({
376393
// eslint-disable-next-line no-param-reassign
377394
fides.cookie = updatedCookie;
378395

379-
// If automated consent was applied, save the cookie to the browser
380-
if (automatedApplied) {
381-
// Set the consentMethod on fides_meta before saving
382-
Object.assign(fides.cookie.fides_meta, {
383-
consentMethod: automatedMethod,
384-
});
385-
386-
await saveFidesCookie(fides.cookie, options);
387-
fidesDebugger(
388-
"Saved automated consent to browser cookie",
389-
fides.cookie,
390-
);
391-
}
392-
393396
// Initialize the i18n singleton before we render the overlay
394397
const i18n = setupI18n();
395398
initializeI18n(

0 commit comments

Comments
 (0)