Skip to content

Instantly share code, notes, and snippets.

@DomDumont
Last active November 22, 2017 15:03
Show Gist options
  • Save DomDumont/cbd0ff279e534ed6219d34f45ab5af92 to your computer and use it in GitHub Desktop.
Save DomDumont/cbd0ff279e534ed6219d34f45ab5af92 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 newUser = {
name: data.name,
email: data.authProvider.email.email,
password: data.authProvider.email.password, // 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