Showing
2 changed files
with
28 additions
and
33 deletions
... | @@ -3,40 +3,35 @@ import bcrypt from "bcryptjs"; | ... | @@ -3,40 +3,35 @@ import bcrypt from "bcryptjs"; |
3 | 3 | ||
4 | export default { | 4 | export default { |
5 | Mutation: { | 5 | Mutation: { |
6 | - resetPassword: async (_, args) => { | 6 | + resetPassword: async (_, args, { request }) => { |
7 | - if (isAuthenticated) { | 7 | + isAuthenticated(request); |
8 | - const { secret, email, passwordOne, passwordTwo } = args; | 8 | + const { emailSecret, email, passwordOne, passwordTwo } = args; |
9 | - const user = await prisma.user.findOne({ | 9 | + const user = await prisma.user.findOne({ |
10 | - where: { | 10 | + where: { |
11 | - email, | 11 | + email, |
12 | - }, | 12 | + }, |
13 | - }); | 13 | + }); |
14 | - const encryptSecret = await bcrypt.hash(user.emailSecret, 10); | 14 | + const encryptSecret = await bcrypt.hash(user.emailSecret, 10); |
15 | - if (encryptSecret !== secret) { | 15 | + if (encryptSecret !== emailSecret) { |
16 | - throw new Error( | 16 | + throw new Error( |
17 | - "not vaild secret value!, input another value or resend email" | 17 | + "not vaild secret value!, input another value or resend email" |
18 | - ); | 18 | + ); |
19 | + } else { | ||
20 | + if (passwordOne !== passwordTwo) { | ||
21 | + // For check new password is right, the two things must be same. | ||
22 | + throw new Error("the two password don't match each other, try again"); | ||
19 | } else { | 23 | } else { |
20 | - if (passwordOne !== passwordTwo) { | 24 | + await prisma.user.update({ |
21 | - // For check new password is right, the two things must be same. | 25 | + where: { |
22 | - throw new Error( | 26 | + email, |
23 | - "the two password don't match each other, try again" | 27 | + }, |
24 | - ); | 28 | + data: { |
25 | - } else { | 29 | + emailSecret: "", |
26 | - await prisma.user.update({ | 30 | + password: passwordOne, |
27 | - where: { | 31 | + }, |
28 | - email, | 32 | + }); |
29 | - }, | ||
30 | - data: { | ||
31 | - emailSecret: "", | ||
32 | - password: passwordOne, | ||
33 | - }, | ||
34 | - }); | ||
35 | - } | ||
36 | - return user; | ||
37 | } | 33 | } |
38 | - } else { | 34 | + return user; |
39 | - throw new Error("You need to login first"); | ||
40 | } | 35 | } |
41 | }, | 36 | }, |
42 | }, | 37 | }, | ... | ... |
-
Please register or login to post a comment