sdy

rename secret to emailSecret

type Mutation {
resetPassword(
secret: String!
emailSecret: String!
email: String!
passwordOne: String!
passwordTwo: String!
......
......@@ -3,40 +3,35 @@ import bcrypt from "bcryptjs";
export default {
Mutation: {
resetPassword: async (_, args) => {
if (isAuthenticated) {
const { secret, email, passwordOne, passwordTwo } = args;
const user = await prisma.user.findOne({
where: {
email,
},
});
const encryptSecret = await bcrypt.hash(user.emailSecret, 10);
if (encryptSecret !== secret) {
throw new Error(
"not vaild secret value!, input another value or resend email"
);
resetPassword: async (_, args, { request }) => {
isAuthenticated(request);
const { emailSecret, email, passwordOne, passwordTwo } = args;
const user = await prisma.user.findOne({
where: {
email,
},
});
const encryptSecret = await bcrypt.hash(user.emailSecret, 10);
if (encryptSecret !== emailSecret) {
throw new Error(
"not vaild secret value!, input another value or resend email"
);
} else {
if (passwordOne !== passwordTwo) {
// For check new password is right, the two things must be same.
throw new Error("the two password don't match each other, try again");
} else {
if (passwordOne !== passwordTwo) {
// For check new password is right, the two things must be same.
throw new Error(
"the two password don't match each other, try again"
);
} else {
await prisma.user.update({
where: {
email,
},
data: {
emailSecret: "",
password: passwordOne,
},
});
}
return user;
await prisma.user.update({
where: {
email,
},
data: {
emailSecret: "",
password: passwordOne,
},
});
}
} else {
throw new Error("You need to login first");
return user;
}
},
},
......