sdy

update findEmail

type Query {
findEmail(phoneNumber: String!): String!
findEmail(phoneNum: String!): Boolean!
}
......
import { prisma, generateSecret, isAuthenticated } from "../../../utils";
import { prisma, isAuthenticated } from "../../../utils";
import twilio from "twilio";
export default {
Query: {
findEmail: async (_, args) => {
if (isAuthenticated) {
const { phoneNumber } = 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);
const randomWords = generateSecret();
client.messages
.create({
body: `Please enter this word : ${randomWords}`,
to: `${phoneNumber}`,
from: "KhuChat",
body: `Your Email is : ${user.email}`,
to: `${phoneNum}`,
from: `${twilioPhone}`,
})
.then((message) => {
console.log(message.sid);
console.log(" --- " + message);
});
const user = await prisma.user.update({
where: {
phoneNumber,
},
data: {
phoneSecret: randomWords,
},
});
return user.email;
return true;
} else {
throw new Error("You need to login first");
}
......