diff --git a/backend-services/src/auth_service/operations/twilio_2fa.py b/backend-services/src/auth_service/operations/twilio_2fa.py index 8162f669f..35c9521fb 100644 --- a/backend-services/src/auth_service/operations/twilio_2fa.py +++ b/backend-services/src/auth_service/operations/twilio_2fa.py @@ -1,3 +1,5 @@ +import asyncio + from fastapi import HTTPException from twilio.rest import Client @@ -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)