findEmail.js
923 Bytes
import { prisma, isAuthenticated } from "../../../utils";
import twilio from "twilio";
export default {
Query: {
findEmail: async (_, args) => {
const { phoneNum } = args;
const user = await prisma.user.findOne({
where: {
phoneNum,
},
});
if (user && isAuthenticated) {
const accountSid = process.env.TWILIO_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const twilioPhone = process.env.TWILIO_PHONE_NUMBER;
const client = new twilio(accountSid, authToken);
client.messages
.create({
body: `Your Email is : ${user.email}`,
to: `${phoneNum}`,
from: `${twilioPhone}`,
})
.then((message) => {
console.log(message.sid);
});
return true;
} else {
throw new Error("You need to login first");
}
},
},
};