(parent, args, context, info)
| 32 | } |
| 33 | |
| 34 | async function login(parent, args, context, info) { |
| 35 | const user = await context.prisma.user.findUnique({ |
| 36 | where: { email: args.email } |
| 37 | }); |
| 38 | if (!user) { |
| 39 | throw new Error('No such user found'); |
| 40 | } |
| 41 | |
| 42 | const valid = await bcrypt.compare( |
| 43 | args.password, |
| 44 | user.password |
| 45 | ); |
| 46 | if (!valid) { |
| 47 | throw new Error('Invalid password'); |
| 48 | } |
| 49 | |
| 50 | const token = jwt.sign({ userId: user.id }, APP_SECRET); |
| 51 | |
| 52 | return { |
| 53 | token, |
| 54 | user |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | async function vote(parent, args, context, info) { |
| 59 | const { userId } = context; |
nothing calls this directly
no outgoing calls
no test coverage detected