Showing
2 changed files
with
25 additions
and
3 deletions
1 | -import { prisma } from "../../../utils"; | 1 | +import { prisma, generateSecret } from "../../../utils"; |
2 | +import twilio from "twilio"; | ||
2 | 3 | ||
3 | export default { | 4 | export default { |
4 | Query: { | 5 | Query: { |
5 | findEmail: async (_, args) => { | 6 | findEmail: async (_, args) => { |
6 | - const { secret } = args; | 7 | + const { phoneNumber } = args; |
8 | + const accountSid = process.env.TWILIO_SID; | ||
9 | + const authToken = process.env.TWILIO_AUTH_TOKEN; | ||
10 | + const client = new twilio(accountSid, authToken); | ||
11 | + const randomWords = generateSecret(); | ||
12 | + client.messages | ||
13 | + .create({ | ||
14 | + body: `Please enter this word : ${randomWords}`, | ||
15 | + to: `${phoneNumber}`, | ||
16 | + from: "KhuChat", | ||
17 | + }) | ||
18 | + .then((message) => console.log(message.sid)); | ||
19 | + | ||
20 | + const user = await prisma.user.update({ | ||
21 | + where: { | ||
22 | + phoneNumber, | ||
23 | + }, | ||
24 | + data: { | ||
25 | + phoneSecret: randomWords, | ||
26 | + }, | ||
27 | + }); | ||
28 | + return user; | ||
7 | }, | 29 | }, |
8 | }, | 30 | }, |
9 | }; | 31 | }; | ... | ... |
-
Please register or login to post a comment