events.on('user.deactivated', function (userModel) { var options = {id: userModel.id}; models.Accesstoken.destroyByUser(options) .then(function () { return models.Refreshtoken.destroyByUser(options); }) .catch(function (err) { logging.error(new errors.GhostError({ err: err, level: 'critical' })); }); });
(function retry() { Promise.props({ accesstokens: models.Accesstoken.findAll({context: {internal: true}, id: userId}), refreshtokens: models.Refreshtoken.findAll({context: {internal: true}, id: userId}) }).then(function (result) { if (retries === 0) { // trigger event after first check how many tokens the user has eventsToRemember['user.deactivated']({ id: userId }); result.accesstokens.length.should.eql(1); result.refreshtokens.length.should.eql(1); } if (!result.accesstokens.length && !result.refreshtokens.length) { return done(); } retries = retries + 1; clearTimeout(timeout); timeout = setTimeout(retry, 500); }).catch(done); })();