sdy

init resetPassword

1 +type Mutation {
2 + resetPassword(
3 + secret: String!
4 + email: String!
5 + passwordOne: String!
6 + passwordTwo: String!
7 + ): User!
8 +}
1 +import { prisma } from "../../../utils";
2 +import bcrypt from "bcryptjs";
3 +
4 +export default {
5 + Mutation: {
6 + resetPassword: async (_, args) => {
7 + const { secret, email, passwordOne, passwordTwo } = args;
8 + const user = await prisma.user.findOne({
9 + where: {
10 + email,
11 + },
12 + });
13 + const encryptSecret = await bcrypt.hash(user.emailSecret, 10);
14 + if (encryptSecret !== secret) {
15 + throw new Error(
16 + "not vaild secret value!, input another value or resend email"
17 + );
18 + } else {
19 + if (passwordOne !== passwordTwo) {
20 + // For check new password is right, the two things must be same.
21 + throw new Error("the two password don't match each other, try again");
22 + } else {
23 + await prisma.user.update({
24 + where: {
25 + email,
26 + },
27 + data: {
28 + emailSecret: "",
29 + password: passwordOne,
30 + },
31 + });
32 + }
33 + return user;
34 + }
35 + },
36 + },
37 +};