Changed tokens type from Array to Mixed to allow overriding existing tokens instead of pushing duplicates

This commit is contained in:
Sahat Yalkabov
2013-11-19 17:28:04 -05:00
parent 0747ee7303
commit 13bd8ef9c8
2 changed files with 8 additions and 4 deletions

View File

@ -15,7 +15,9 @@ var foursquareAccessToken = 'MY_FOURSQUARE_ACCESS_TOKEN';
exports.apiBrowser = function(req, res) { exports.apiBrowser = function(req, res) {
res.render('api'); res.render('api', {
title: 'API Browser'
});
}; };
@ -44,8 +46,10 @@ exports.foursquareAuth = function(req, res) {
exports.foursquareCallback = function(req, res) { exports.foursquareCallback = function(req, res) {
foursquare.getAccessToken({ code: req.query.code }, function(err, accessToken) { foursquare.getAccessToken({ code: req.query.code }, function(err, accessToken) {
if (err) throw err; if (err) throw err;
User.findByIdAndUpdate(req.user._id, { $set: { tokens: { foursquare: accessToken } } }, null, function(err, user) {
console.log(accessToken); if (err) throw err;
res.redirect('/api/foursquare');
});
}); });
}; };

View File

@ -7,7 +7,7 @@ var userSchema = new mongoose.Schema({
firstName: String, firstName: String,
lastName: String, lastName: String,
password: String, password: String,
tokens: Array, tokens: mongoose.Schema.Types.Mixed,
provider: String, provider: String,
facebook: String, facebook: String,
google: String google: String