Django-allauth - Make phone number optional for SocialLogin

Django-allauth - Make phone number optional for SocialLogin

I am using django-allauth in my project and I have configured Google as a SocialAuth provider. I have a custom signal receiver that updates the phone number on the SocialAuthAccount after the user signs up. But currently the system throws an error when the user logins via SocialAuth if they do not have a public phone number on their account. I am getting an error - KeyError 'phone' at - allauth/account/internal/flows/phone_verification.py - line 46.

This is my relevant settings.py:

ACCOUNT_LOGIN_METHODS = {"phone", "email", "username"}
ACCOUNT_SIGNUP_FIELDS = [
    "phone*",
    "email*",
    "username*",
    "password1",
    "password2"
]

How can I tell the SocialAuthAdapter that phone number is optional and might not be there?

Answer

I have an idea, if the phone number is optional, you can do the following set up. I tells allauth than the phone number is optional.

ACCOUNT_SIGNUP_FIELDS = [
    "phone",  # <-- remove the asterisk (*)
    "email*",
    "username*",
    "password1",
    "password2"
]

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions