Created
November 23, 2017 13:16
-
-
Save DomDumont/6b2db2ab7210c2aba4a6a6446bc1b3b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createUser: async (root, data, { mongo: { Users } }) => { | |
const user = await Users.findOne({ email: data.authProvider.email.email }); | |
if (user) { | |
// a user with the same email was found, throw an error | |
throw new Error("Email already exists"); | |
} | |
const hash = await bcrypt.hash(data.authProvider.email.password, 10); | |
const newUser = { | |
name: data.name, | |
email: data.authProvider.email.email, | |
password: hash, // todo this is really bad, do not store password in clear | |
}; | |
const response = await Users.insert(newUser); | |
return { id: response.insertedIds[0], ...newUser }; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment