sdy

update login resolver codes

......@@ -4,24 +4,21 @@ import jwt from "jsonwebtoken";
export default {
Mutation: {
login: async (_, args, context) => {
login: async (_, args) => {
const { email, password } = args;
const user = await prisma.user.findOne({
where: {
email,
},
});
if (!user) {
throw new Error("There is no such user");
let vaild;
if (user) {
vaild = await bcrypt.compare(password, user.password);
}
const vaild = await bcrypt.compare(password, user.password);
if (!vaild) {
throw new Error("Invaild Password!");
if (!user || !vaild) {
throw new Error("Not vaild email or password");
}
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET);
return { token, user };
},
},
......