Skip to content

Instantly share code, notes, and snippets.

@DomDumont
Created November 23, 2017 13:16
Show Gist options
  • Save DomDumont/6b2db2ab7210c2aba4a6a6446bc1b3b0 to your computer and use it in GitHub Desktop.
Save DomDumont/6b2db2ab7210c2aba4a6a6446bc1b3b0 to your computer and use it in GitHub Desktop.
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