Last active
November 26, 2017 18:00
-
-
Save DomDumont/0b61c7cd8e9f5f20b476c8c24330db9b 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
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