Skip to content

Commit

Permalink
fix(backend-services): set correct event loop for OTP Twilio async call
Browse files Browse the repository at this point in the history
  • Loading branch information
billguo99 committed May 22, 2023
1 parent cd10a73 commit 720b62e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend-services/src/auth_service/operations/twilio_2fa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

from fastapi import HTTPException
from twilio.rest import Client

Expand All @@ -13,10 +15,15 @@
async def send_otp_to_user(
settings: AppSettings, client: Client, params: SendOtp
) -> SendOtpResponse:
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop) # Set the Twilio client's event loop as the default

verification = await client.verify.v2.services(
settings.twilio_service_sid
).verifications.create_async(to=params.phone_number, channel="sms")

asyncio.set_event_loop(None) # Reset the default event loop

if verification.sid is None:
raise HTTPException(500)
return SendOtpResponse(verification_sid=verification.sid)
Expand Down

0 comments on commit 720b62e

Please sign in to comment.