sdy

add isAuthenticated middleware

1 -import { prisma } from "../../../utils"; 1 +import { prisma, isAuthenticated } from "../../../utils";
2 import bcrypt from "bcryptjs"; 2 import bcrypt from "bcryptjs";
3 3
4 export default { 4 export default {
5 Mutation: { 5 Mutation: {
6 resetPassword: async (_, args) => { 6 resetPassword: async (_, args) => {
7 + if (isAuthenticated) {
7 const { secret, email, passwordOne, passwordTwo } = args; 8 const { secret, email, passwordOne, passwordTwo } = args;
8 const user = await prisma.user.findOne({ 9 const user = await prisma.user.findOne({
9 where: { 10 where: {
...@@ -18,7 +19,9 @@ export default { ...@@ -18,7 +19,9 @@ export default {
18 } else { 19 } else {
19 if (passwordOne !== passwordTwo) { 20 if (passwordOne !== passwordTwo) {
20 // 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.
21 - throw new Error("the two password don't match each other, try again"); 22 + throw new Error(
23 + "the two password don't match each other, try again"
24 + );
22 } else { 25 } else {
23 await prisma.user.update({ 26 await prisma.user.update({
24 where: { 27 where: {
...@@ -32,6 +35,9 @@ export default { ...@@ -32,6 +35,9 @@ export default {
32 } 35 }
33 return user; 36 return user;
34 } 37 }
38 + } else {
39 + throw new Error("You need to login first");
40 + }
35 }, 41 },
36 }, 42 },
37 }; 43 };
......