Showing
2 changed files
with
6 additions
and
11 deletions
... | @@ -3,25 +3,23 @@ import bcrypt from "bcryptjs"; | ... | @@ -3,25 +3,23 @@ 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 { | 19 | } else { |
20 | if (passwordOne !== passwordTwo) { | 20 | if (passwordOne !== passwordTwo) { |
21 | // For check new password is right, the two things must be same. | 21 | // For check new password is right, the two things must be same. |
22 | - throw new Error( | 22 | + throw new Error("the two password don't match each other, try again"); |
23 | - "the two password don't match each other, try again" | ||
24 | - ); | ||
25 | } else { | 23 | } else { |
26 | await prisma.user.update({ | 24 | await prisma.user.update({ |
27 | where: { | 25 | where: { |
... | @@ -35,9 +33,6 @@ export default { | ... | @@ -35,9 +33,6 @@ export default { |
35 | } | 33 | } |
36 | return user; | 34 | return user; |
37 | } | 35 | } |
38 | - } else { | ||
39 | - throw new Error("You need to login first"); | ||
40 | - } | ||
41 | }, | 36 | }, |
42 | }, | 37 | }, |
43 | }; | 38 | }; | ... | ... |
-
Please register or login to post a comment