diff --git a/app/onboarding/mutations/set-phone-number.ts b/app/onboarding/mutations/set-phone-number.ts index 2b2f1c6..388f02e 100644 --- a/app/onboarding/mutations/set-phone-number.ts +++ b/app/onboarding/mutations/set-phone-number.ts @@ -1,12 +1,12 @@ import { resolver } from "blitz"; import { z } from "zod"; +import twilio from "twilio"; import db from "../../../db"; import getCurrentUser from "../../users/queries/get-current-user"; import fetchMessagesQueue from "../../messages/api/queue/fetch-messages"; import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls"; import setTwilioWebhooks from "../api/queue/set-twilio-webhooks"; -import getTwilioClient from "../../../integrations/twilio"; const Body = z.object({ phoneNumberSid: z.string(), @@ -15,12 +15,14 @@ const Body = z.object({ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ phoneNumberSid }, context) => { const user = await getCurrentUser(null, context); const organization = user?.memberships[0]!.organization; - if (!user || !organization) { + if (!user || !organization || !organization.twilioAccountSid || !organization.twilioAuthToken) { return; } - const twilioClient = getTwilioClient(organization); - const phoneNumbers = await twilioClient.incomingPhoneNumbers.list(); + const phoneNumbers = await twilio( + organization.twilioAccountSid, + organization.twilioAuthToken, + ).incomingPhoneNumbers.list(); const phoneNumber = phoneNumbers.find((phoneNumber) => phoneNumber.sid === phoneNumberSid)!; const organizationId = organization.id; await db.phoneNumber.create({ diff --git a/app/onboarding/pages/welcome/step-three.tsx b/app/onboarding/pages/welcome/step-three.tsx index a182715..df27e52 100644 --- a/app/onboarding/pages/welcome/step-three.tsx +++ b/app/onboarding/pages/welcome/step-three.tsx @@ -3,11 +3,11 @@ import { Routes, getSession, useRouter, useMutation } from "blitz"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import clsx from "clsx"; +import twilio from "twilio"; import db from "../../../../db"; import OnboardingLayout from "../../components/onboarding-layout"; import setPhoneNumber from "../../mutations/set-phone-number"; -import getTwilioClient from "../../../../integrations/twilio"; type PhoneNumber = { phoneNumber: string; @@ -130,8 +130,10 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res } }; } - const twilioClient = getTwilioClient(organization); - const incomingPhoneNumbers = await twilioClient.incomingPhoneNumbers.list(); + const incomingPhoneNumbers = await twilio( + organization.twilioAccountSid, + organization.twilioAuthToken, + ).incomingPhoneNumbers.list(); const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid })); return { diff --git a/app/users/queries/get-current-user.ts b/app/users/queries/get-current-user.ts index 7fb0cf4..6176464 100644 --- a/app/users/queries/get-current-user.ts +++ b/app/users/queries/get-current-user.ts @@ -21,6 +21,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) { paddleCustomerId: true, paddleSubscriptionId: true, twilioAccountSid: true, + twilioAuthToken: true, twilioApiKey: true, twilioApiSecret: true, twimlAppSid: true,