I am creating a Sign Up With Google+ API. When inserting data into my Users table, I want to get the user's email. I get an error when trying to do that. My code looks like this:
var API_KEY = 'A*****';
plus.people.get({
auth: API_KEY,
userId: req.body.userID
}, function (err, user) {
if( err ) { res.json( JSON.stringify( err ) ); return; }
console.log(user.emails);
User.find({ where:{ social_id:req.body.userID, type: 2 } }).then( existingUser =>{
if( existingUser ) throw new Error('social_user_existing');
if(!existingUser){
User.build({
username: user.displayName,
social_id : req.body.userID,
social_token :req.body.token,
type : 2
}).save();
}
}).then(function( new_g_user ){
return res.json( rs.success({ username: user.displayName, user_id: user.id, jwt: new_g_user.getJwt() }) );
}).catch(function(err){
res.json( rs.errorCode(err.message) );
});
});
I tried to get the email of the user with user.emails and user.emails[0].value to get at least the value of the first email. Each time, the response was 'undefined'. I mention that user.kind is 'plus#person'
, not "plus#personOpenIdConnect"
. Can this cause the response I get? Thank you!
via Emanuela colta
No comments:
Post a Comment