findEmail.js 819 Bytes
import { prisma, generateSecret } from "../../../utils";
import twilio from "twilio";

export default {
  Query: {
    findEmail: async (_, args) => {
      const { phoneNumber } = args;
      const accountSid = process.env.TWILIO_SID;
      const authToken = process.env.TWILIO_AUTH_TOKEN;
      const client = new twilio(accountSid, authToken);
      const randomWords = generateSecret();
      client.messages
        .create({
          body: `Please enter this word : ${randomWords}`,
          to: `${phoneNumber}`,
          from: "KhuChat",
        })
        .then((message) => console.log(message.sid));

      const user = await prisma.user.update({
        where: {
          phoneNumber,
        },
        data: {
          phoneSecret: randomWords,
        },
      });
      return user;
    },
  },
};