Last active
August 29, 2015 14:11
-
-
Save spencerhunter/a3cc22b0a5f898c188f3 to your computer and use it in GitHub Desktop.
Refresh token - node-cron example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cron = require('cron'); | |
var cronJob = cron.job("0 */55 * * * *", function() { | |
User.find({ | |
where: { | |
dwolla_id: '812-196-0757' //query user in db | |
} | |
}).then(function(user) { | |
if (user) { //if user exists in db | |
var rToken = user.dwolla_refresh; //grab the existing stored refresh token | |
Dwolla.refreshAuth(rToken, function(error, auth) { //pass refresh token into refreshAuth request | |
if (error) { | |
return console.log(error); | |
} | |
user.updateAttributes({ | |
dwolla_refresh: auth.refresh_token //From response, set new refresh token in db | |
}).success(function() { | |
console.log("updated"); | |
}) | |
}); | |
} else { | |
console.log("user does not exist"); | |
} | |
}). | |
catch (function(err) { | |
console.log(err); | |
}) | |
console.info('cron job completed'); | |
}); | |
cronJob.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment