From a910fc165141a675e0591d9a5c33e43982f1baf5 Mon Sep 17 00:00:00 2001 From: Yvo van Doorn Date: Sat, 6 Jun 2020 19:49:43 +0200 Subject: [PATCH] add commented ability to set version of consent given --- rules.json | 2 +- src/rules/track-consent.js | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/rules.json b/rules.json index b263a527..6e613d0b 100644 --- a/rules.json +++ b/rules.json @@ -336,7 +336,7 @@ "enrich profile" ], "description": "

This rule will add two attributes to the user's metadata object on when they accepted the terms and conditions.

\n

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.

", - "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}" } ] }, diff --git a/src/rules/track-consent.js b/src/rules/track-consent.js index 3da45799..1d0d9322 100644 --- a/src/rules/track-consent.js +++ b/src/rules/track-consent.js @@ -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); }); - } \ No newline at end of file +} \ No newline at end of file