findEmail.js
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { prisma, generateSecret, isAuthenticated } from "../../../utils";
import twilio from "twilio";
export default {
Query: {
findEmail: async (_, args) => {
if (isAuthenticated) {
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);
console.log(" --- " + message);
});
const user = await prisma.user.update({
where: {
phoneNumber,
},
data: {
phoneSecret: randomWords,
},
});
return user.email;
} else {
throw new Error("You need to login first");
}
},
},
};