AM
const login = async (_, { email, password }, ctx, info) => {
const user = await ctx.db.query.user({
where: {
email: email
}
})
if (!user) {
throw new Error(`No such user found for email or login`)
}
const valid = await bcrypt.compare(password, user.password)
if (!valid) {
throw new Error('Invalid password')
}
return {
token: jwt.sign({ userId: user.id }, "bbapi"),
user
}
}