Skip to content

Fix Accept All button incorrectly recording rejected consent#158

Open
fvholten wants to merge 1 commit into
pressidium:masterfrom
fvholten:fix/accept-all-consent-recording
Open

Fix Accept All button incorrectly recording rejected consent#158
fvholten wants to merge 1 commit into
pressidium:masterfrom
fvholten:fix/accept-all-consent-recording

Conversation

@fvholten

Copy link
Copy Markdown

Summary

Fixes a critical bug where the "Accept All" button was incorrectly marking all cookie categories as rejected in the consent records instead of accepted.

Problem Description

When users clicked the "Accept All" button on the cookie consent modal, the consent would be processed correctly (cookies would be allowed), but the consent records stored in the database would incorrectly show all cookie categories (necessary, analytics, targeting, preferences) as false instead of true.

Root Cause Analysis

The issue was in the updateConsentRecords function in src/client/index.js (lines 215-218). The function was using a fragile approach to determine accepted categories:

// Problematic approach
necessary_consent: cookie.level.includes('necessary'),
analytics_consent: cookie.level.includes('analytics'),
targeting_consent: cookie.level.includes('targeting'),
preferences_consent: cookie.level.includes('preferences'),

This logic failed to properly detect accepted categories when the "Accept All" functionality was triggered.

Solution

Improved the consent recording logic with a more robust approach:

// Improved approach with fallback
const acceptedCategories = cookie.categories || cookie.level || [];
necessary_consent: acceptedCategories.includes('necessary'),
analytics_consent: acceptedCategories.includes('analytics'),
targeting_consent: acceptedCategories.includes('targeting'),
preferences_consent: acceptedCategories.includes('preferences'),

Changes Made

  • Enhanced category detection: Uses both cookie.categories and cookie.level with proper fallback logic
  • Improved robustness: Ensures consent recording works regardless of cookie data structure variations
  • Maintained compatibility: Preserves existing functionality for all other consent scenarios

Testing

  • ✅ Verified "Accept All" now correctly records all categories as accepted (true)
  • ✅ Confirmed selective category acceptance still works correctly
  • ✅ Ensured existing functionality remains unaffected
  • ✅ Built and tested the minified production bundle

Impact

  • Users: Consent preferences are now accurately recorded when using "Accept All"
  • Compliance: Proper audit trail for GDPR/CCPA compliance requirements
  • Analytics: Accurate consent data for reporting and analytics

This fix ensures that consent records accurately reflect user choices, which is critical for legal compliance and data governance.

🤖 Generated with Claude Code

The "Accept All" button was incorrectly marking all cookie categories
as rejected in the consent records instead of accepted. This occurred
because the consent recording logic in updateConsentRecords() relied
solely on cookie.level.includes() without proper fallback handling.

Changes:
- Improved category detection logic with fallback between cookie.categories and cookie.level
- Added more robust consent recording that works regardless of cookie data structure
- Ensures all categories are properly recorded as accepted when "Accept All" is clicked

Fixes the issue where consent records showed all categories as false
instead of true when users clicked "Accept All".

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant