sdy

update confirmEmailSecret

1 +type Mutation {
2 + confirmEmailSecret(secret: String!, email: String!): String!
3 +}
1 +import { prisma, generateToken } from "../../../utils";
2 +
3 +export default {
4 + Mutation: {
5 + confirmEmailSecret: async (_, args) => {
6 + const { secret, email } = args;
7 + const user = await prisma.user.findOne({
8 + where: {
9 + email,
10 + },
11 + });
12 + if (user.emailSecret !== secret) {
13 + throw new Error(
14 + "not vaild secret value!, input another value or resend email"
15 + );
16 + } else {
17 + // TODO: Update emailSecret in prisma
18 + await prisma.user.update({
19 + where: {
20 + email,
21 + },
22 + data: {
23 + emailSecret: "",
24 + },
25 + });
26 + return generateToken(user.id);
27 + }
28 + },
29 + },
30 +};