Skip to content

Commit

Permalink
Merge pull request #236 from yvovandoorn/simple-consent/02
Browse files Browse the repository at this point in the history
Track Consent Rule - add commented ability to set version of consent given
  • Loading branch information
Chris Geihsler authored Jun 6, 2020
2 parents c388781 + a910fc1 commit 4059850
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"enrich profile"
],
"description": "<p>This rule will add two attributes to the user's metadata object on when they accepted the terms and conditions.</p>\n<p>This is useful for cases where you want to track an user's consent. See https://auth0.com/docs/compliance/gdpr/features-aiding-compliance/user-consent/track-consent-with-lock for more information.</p>",
"code": "function (user, context, callback) {\n user.user_metadata = user.user_metadata || {};\n // short-circuit if the user signed up already\n if (user.user_metadata.consentGiven) return callback(null, user, context);\n \n // first time login/signup\n user.user_metadata.consentGiven = true;\n user.user_metadata.consentTimestamp = Date.now();\n auth0.users.updateUserMetadata(user.user_id, user.user_metadata)\n .then(function(){\n callback(null, user, context);\n })\n .catch(function(err){\n callback(err);\n });\n }"
"code": "function trackConsent(user, context, callback) {\n user.user_metadata = user.user_metadata || {};\n // short-circuit if the user signed up already\n if (user.user_metadata.consentGiven) return callback(null, user, context);\n\n // first time login/signup\n user.user_metadata.consentGiven = true;\n // uncomment to track consentVersion\n // user.user_metadata.consentVersion = \"1.9\";\n\n user.user_metadata.consentTimestamp = Date.now();\n auth0.users.updateUserMetadata(user.user_id, user.user_metadata)\n .then(function () {\n callback(null, user, context);\n })\n .catch(function (err) {\n callback(err);\n });\n}"
}
]
},
Expand Down
27 changes: 15 additions & 12 deletions src/rules/track-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@
*
*/

function (user, context, callback) {
user.user_metadata = user.user_metadata || {};
// short-circuit if the user signed up already
if (user.user_metadata.consentGiven) return callback(null, user, context);

// first time login/signup
user.user_metadata.consentGiven = true;
user.user_metadata.consentTimestamp = Date.now();
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function(){
function trackConsent(user, context, callback) {
user.user_metadata = user.user_metadata || {};
// short-circuit if the user signed up already
if (user.user_metadata.consentGiven) return callback(null, user, context);

// first time login/signup
user.user_metadata.consentGiven = true;
// uncomment to track consentVersion
// user.user_metadata.consentVersion = "1.9";

user.user_metadata.consentTimestamp = Date.now();
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function () {
callback(null, user, context);
})
.catch(function(err){
.catch(function (err) {
callback(err);
});
}
}

0 comments on commit 4059850

Please sign in to comment.