Skip to content

Instantly share code, notes, and snippets.

@DomDumont
Last active November 26, 2017 18:00
Show Gist options
  • Save DomDumont/0b61c7cd8e9f5f20b476c8c24330db9b to your computer and use it in GitHub Desktop.
Save DomDumont/0b61c7cd8e9f5f20b476c8c24330db9b to your computer and use it in GitHub Desktop.
signinUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.email.email });
if (user === null) {
throw new Error("Email not found !!");
}
const passwordIsGood = await bcrypt.compare(data.email.password, user.password);
if (passwordIsGood) {
const newToken = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, { expiresIn: "1h" });
return { token: newToken, user };
} else {
throw new Error("Bad Password !!");
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment