app/controllers/users/users.authentication.server.controller.js
/**
 * Helper function to update a OAuth user profile with spotify
 */
Helper function to update a OAuth user profile with spotify
Helper function to update a OAuth user profile with spotify
function updateSpotifyProfile (req, providerUserProfile, callback) {
    if(req.user){
        User.findOne({_id: req.user._id}).select({_id: 1, additionalProvidersData: 1 }).exec(function(err, user) {
            if (err) return callback(err, null);
            providerUserProfile.provider = 'spotify';
            if (user.provider !== providerUserProfile.provider && (!user.additionalProvidersData || !user.additionalProvidersData[providerUserProfile.provider])) {
                if (!user.additionalProvidersData) user.additionalProvidersData = {};
                user.additionalProvidersData[providerUserProfile.provider]=providerUserProfile;
                user.markModified('additionalProvidersData');
                user.save(function(err) {
                    req.user.additionalProvidersData = user.additionalProvidersData;
                    return callback (null, req.user);
                });
            }else{
                return callback (null, req.user);
            }
    	});
    }       
}
function updateSpotifyProfile ( req , providerUserProfile , callback ) { if ( req . user ) { User . findOne ( { _id : req . user . _id } ) . select ( { _id : 1 , additionalProvidersData : 1 } ) . exec ( function ( err , user ) { if ( err ) return callback ( err , null ) ; providerUserProfile . provider = 'spotify' ; if ( user . provider !== providerUserProfile . provider && ( ! user . additionalProvidersData || ! user . additionalProvidersData [ providerUserProfile . provider ] ) ) { if ( ! user . additionalProvidersData ) user . additionalProvidersData = { } ; user . additionalProvidersData [ providerUserProfile . provider ] = providerUserProfile ; user . markModified ( 'additionalProvidersData' ) ; user . save ( function ( err ) { req . user . additionalProvidersData = user . additionalProvidersData ; return callback ( null , req . user ) ; } ) ; } else { return callback ( null , req . user ) ; } } ) ; } }
Helper function to update a OAuth user profile with spotify
Helper function to update a OAuth user profile with spotify
// Then tell mongoose that we've updated the additionalProvidersData field //    console.log('update spotify after markmodified'); // And save the user //return callback (null, user);