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