todos-contra-el-fuego-web/imports/modules/get-email-of-user.js
2018-03-05 09:59:55 +01:00

19 lines
698 B
JavaScript

/* eslint-disable import/no-absolute-path */
import getOAuthProfile from '/imports/modules/get-oauth-profile';
const getEmailOf = (user) => {
const hasPassword = user.services && user.services.password && user.services.password.bcrypt;
// console.log(`Has password: ${hasPassword}`);
const OAuthProfile = getOAuthProfile({
password: hasPassword,
profile: user.profile
}, user);
const firstName = OAuthProfile ? OAuthProfile.name.first : user.profile.name.first;
const emailAddress = OAuthProfile ? OAuthProfile.email :
user && user.emails[0] && user.emails[0].verified ? user.emails[0].address : null;
return { emailAddress, firstName };
};
export default getEmailOf;