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