diff --git a/api/helpers/passport.js b/api/helpers/passport.js index 0879682..7b5381f 100644 --- a/api/helpers/passport.js +++ b/api/helpers/passport.js @@ -117,7 +117,7 @@ function PassportHelper () { // if the profile object from passport has an email, use it if (profile.emails && profile.emails[0]) userAttrs.email = profile.emails[0].value - if (!userAttrs.email) return next(new Error('No email available')) + // if (!userAttrs.email) return next(new Error('No email available')) const pass = await Passport.findOne({ provider, @@ -128,7 +128,9 @@ function PassportHelper () { if (!req.user) { if (!pass) { // new user signing up, create a new user and/or passport - user = await User.findOne({ email: userAttrs.email }) + if (userAttrs.email) { + user = await User.findOne({ email: userAttrs.email }) + } if (!user) { user = await User.create(userAttrs).fetch() } diff --git a/api/models/User.js b/api/models/User.js index 480dfe2..c8e0292 100644 --- a/api/models/User.js +++ b/api/models/User.js @@ -17,9 +17,7 @@ module.exports = { autoIncrement: true }, email: { - type: 'string', - unique: true, - required: true + type: 'string' } // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ diff --git a/assets/js/actions/index.js b/assets/js/actions/index.js index 8f1f566..fa57a66 100644 --- a/assets/js/actions/index.js +++ b/assets/js/actions/index.js @@ -131,7 +131,7 @@ export const editUser = (user) => async (dispatch, getState) => { dispatch(setWorking(true)) try { - if (!user.currentPassword) throw new Error('Please enter your current password.') + // if (!user.currentPassword) throw new Error('Please enter your current password.') await Ajax.patch({ url: '/api/me', data: { diff --git a/config/protocols.js b/config/protocols.js index aed2dbe..a4ae57c 100644 --- a/config/protocols.js +++ b/config/protocols.js @@ -70,17 +70,19 @@ module.exports.protocols = { const dbUser = await User.findOne({ id: user.id }) - if (!dbUser) throw new Error('an account with that id was not found') + if (!dbUser) throw new Error('An account with that id was not found.') const passport = await Passport.findOne({ protocol: 'local', user: user.id }) - if (!user.currentPassword && passport) throw new Error('Missing current password') + if (!user.currentPassword && passport) throw new Error('Please enter your current password.') if (passport) { const res = await Passport.validatePassword(user.currentPassword, passport) if (!res) throw new Error('incorrect password') + const otherUser = await User.findOne({ email: user.email }) + if (otherUser && otherUser.id !== dbUser.id) throw new Error('There is already an account with that email.') await User.update({ id: user.id }, { email: user.email }) @@ -90,6 +92,8 @@ module.exports.protocols = { }) } } else { // no password yet, add one + const otherUser = await User.findOne({ email: user.email }) + if (otherUser && otherUser.id !== dbUser.id) throw new Error('There is already an account with that email.') await User.update({ id: user.id }, { email: user.email })