diff --git a/library.js b/library.js index 82e557e..813f216 100644 --- a/library.js +++ b/library.js @@ -232,5 +232,27 @@ }); }; + OAuth.deleteUserData = function(uid) { + db.getObject('oAuthid:uid', function(err, oAuthData) { + if (err) { + winston.error('Could not fetch OAuthId data from Redis. Error: ' + err); + } + var oAuthIdToDelete; + for (var oAuthId in oAuthData) { + if (oAuthData.hasOwnProperty(oAuthId) && oAuthData[oAuthId] === uid) { + oAuthIdToDelete = oAuthId; + } + } + if (typeof oAuthIdToDelete !== 'undefined') { + // Delete the oAuthId-to-uid mapping for the user + db.deleteObjectField('oAuthid:uid', oAuthIdToDelete, function(err, numDeletes) { + if (err) { + winston.error('Could not remove OAuthId data for uid ' + uid + '. Error: ' + err); + } + }); + } + }); + }; + module.exports = OAuth; }(module)); \ No newline at end of file diff --git a/plugin.json b/plugin.json index ead46d0..687b124 100644 --- a/plugin.json +++ b/plugin.json @@ -6,6 +6,7 @@ "library": "./library.js", "hooks": [ { "hook": "action:app.load", "method": "init" }, + { "hook": "action:user.delete", "method": "deleteUserData" }, { "hook": "filter:auth.init", "method": "getStrategy" }, { "hook": "filter:admin.header.build", "method": "addMenuItem" } ],