Skip to content

Commit ffa7e53

Browse files
authored
fix: non-EU users get all consent granted without storing (#71)
- Grant all categories (including marketing) for non-EU users - Don't store consent on init — it's the default state for unrestricted jurisdictions - Consent only stored when user explicitly changes preferences - Add test verifying no cookie is set for non-EU on init Closes #70
1 parent 082e0ec commit ffa7e53

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/__tests__/consent-manager.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ describe("ConsentManager banner deferred show (bannerPending)", () => {
210210
// Non-EU user: banner never shown, bannerPending stays false
211211
expect(showBanner).not.toHaveBeenCalled();
212212
});
213+
214+
it("does not store consent for non-EU user on init (default state)", async () => {
215+
// Ensure no cookies exist before test
216+
cookieStore = "";
217+
218+
const manager = new ConsentManager({
219+
geoDetector: createMockGeoDetector(false),
220+
version: "1.0",
221+
});
222+
223+
await manager.init();
224+
225+
// Non-EU user: consent is applied but NOT stored (it's the default state)
226+
// No consent_preferences cookie should be set
227+
expect(cookieStore).not.toContain("consent_preferences");
228+
229+
// But hasConsent() should return false (no stored consent)
230+
expect(manager.hasConsent()).toBe(false);
231+
232+
// getConsent() should return null (nothing stored)
233+
expect(manager.getConsent()).toBeNull();
234+
});
213235
});
214236

215237
describe("ConsentManager.getGeoResult()", () => {

src/core/consent-manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,16 @@ export class ConsentManager {
199199
}
200200
this.config.onBannerShow?.();
201201
} else {
202-
// Non-EU user: grant consent silently
202+
// Non-EU user: grant all consent silently (same as "Accept All").
203+
// Don't store — this is the default state for unrestricted jurisdictions.
204+
// Consent will only be stored if user explicitly changes preferences.
203205
const grantedCategories = {
204206
analytics: true,
205-
marketing: this.config.categories?.marketing ?? false,
207+
marketing: true,
206208
functional: true,
207209
};
208210

209211
await this.applyConsent(grantedCategories);
210-
this.saveConsentWithRemote(grantedCategories);
211212
}
212213
}
213214

0 commit comments

Comments
 (0)