Skip to content

Commit

Permalink
Merge pull request #109 from andela/bg-fix-social-login-duplicate-ema…
Browse files Browse the repository at this point in the history
…il-166974705

Bug fix duplicate account on social login #166974705
  • Loading branch information
jnkindi committed Jun 28, 2019
2 parents 0d56aa9 + 78a38d9 commit 04874c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ const UserModel = (Sequelize, DataTypes) => {
role: { type: DataTypes.STRING, allowNull: false, defaultValue: 'User' }
});
User.socialUsers = async userProfile => {
//
const { email } = userProfile;
if (email) {
const userInfo = await User.findOne({ where: { email } });
if (userInfo) {
const userId = userInfo.id;
//
const { provider } = userProfile;
const { provideruserid } = userProfile;
const result = await User.update({ provider, provideruserid }, { where: { id: userId }, returning: true });
return result[1][0].dataValues;
}
}
//
const result = await User.findOrCreate({
where: { provideruserid: userProfile.provideruserid },
defaults: userProfile
Expand Down

0 comments on commit 04874c5

Please sign in to comment.