Skip to content

Commit

Permalink
chore(auth): edit email (#65)
Browse files Browse the repository at this point in the history
- edit the way to get email from third party

[Finishes #167284653]
  • Loading branch information
jabichris authored and Titilope Morolari committed Jul 25, 2019
1 parent e2df1b5 commit 0875c78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserController {
);
if (isValidPassword) {
const token = helper.generateToken(userExist.dataValues);
return res.redirect(`${process.env.FRONTEND_URL}/articles?token=${token}&username=${req.user.username}`);
return res.redirect(`${process.env.FRONTEND_URL}/login?token=${token}&username=${req.user.username}&image=${req.user.image}`);
}
return res.redirect(`${process.env.FRONTEND_URL}/verify/409`);
}
Expand All @@ -47,7 +47,7 @@ class UserController {
return res.status(500).send('Internal error');
}
const token = helper.generateToken(newUser.dataValues);
return res.redirect(`${process.env.FRONTEND_URL}/articles?token=${token}&username=${req.user.username}`);
return res.redirect(`${process.env.FRONTEND_URL}/login?token=${token}&username=${req.user.username}`);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions helpers/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class PassportHelper {
let user;
try {
const userName = profile.username || profile.name.familyName || profile.name.givenName;
const email = profile.emails[0].value;
const email = profile.emails ? profile.emails[0].value : '';
const username = userName || email.substring(0, email.indexOf('@'));
user = {
username: userName || email.substring(0, email.indexOf('@')),
email: profile.emails[0].value,
username,
email,
password: profile.id,
provider: profile.provider
provider: profile.provider,
image: profile.picture
};
done(null, user);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const users = (sequelize, DataTypes) => {
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false
allowNull: true
},
bio: {
type: DataTypes.STRING,
Expand Down

0 comments on commit 0875c78

Please sign in to comment.