Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend-services): set correct event loop for OTP Twilio async call #567

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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