requestEmailSecret.js 668 Bytes
import { prisma, generateSecret, sendSecretMail } from "../../../utils";
import bcrypt from "bcryptjs";

export default {
  Mutation: {
    requestEmailSecret: async (_, args) => {
      const { email } = args;
      const emailSecret = generateSecret();
      const encryptSecret = await bcrypt.hash(emailSecret, 10);
      try {
        await sendSecretMail(email, emailSecret);
        await prisma.user.update({
          where: {
            email,
          },
          data: {
            emailSecret: encryptSecret,
          },
        });
        return true;
      } catch (error) {
        console.log(error);
        return false;
      }
    },
  },
};