Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 };
- },
Add Comment
Please, Sign In to add comment