diff --git a/library.js b/library.js index 813f216..8aa7d1b 100644 --- a/library.js +++ b/library.js @@ -9,6 +9,7 @@ path = module.parent.require('path'), nconf = module.parent.require('nconf'), winston = module.parent.require('winston'), + async = module.parent.require('async'), passportOAuth; var constants = Object.freeze({ @@ -232,25 +233,18 @@ }); }; - OAuth.deleteUserData = function(uid) { - db.getObject('oAuthid:uid', function(err, oAuthData) { + OAuth.deleteUserData = function(uid, callback) { + async.waterfall([ + async.apply(User.getUserField, uid, 'oAuthid'), + function(oAuthIdToDelete, next) { + db.deleteObjectField('oAuthid:uid', oAuthIdToDelete, next); + } + ], function(err) { 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); - } - }); + winston.error('Could not remove OAuthId data for uid ' + uid + '. Error: ' + err); + return callback(err); } + callback(); }); }; diff --git a/plugin.json b/plugin.json index 687b124..f627401 100644 --- a/plugin.json +++ b/plugin.json @@ -6,7 +6,7 @@ "library": "./library.js", "hooks": [ { "hook": "action:app.load", "method": "init" }, - { "hook": "action:user.delete", "method": "deleteUserData" }, + { "hook": "filter:user.delete", "method": "deleteUserData" }, { "hook": "filter:auth.init", "method": "getStrategy" }, { "hook": "filter:admin.header.build", "method": "addMenuItem" } ],