Search code examples
djangodjango-allauth

How to skip user sign up form presented by django-allauth when signing up through social sites?


Recently, I ran into something unusual. When i tried to sign up on my django site through Linked In it logged me in right away and redirected me to whatever the login redirect URL i had set. But now when I finnaly deployed my site on AWS, django-allauth takes me to this user sign up page asking for username before sign up. I would like to skip this and use the email instead of "username". Here are my django all auth specific settings from settings.py:
ACCOUNT_AUTHENTICATION_METHOD = "email" ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_VERIFICATION = "none" ACCOUNT_LOGOUT_REDIRECT_URL = "/user/" ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True ACCOUNT_UNIQUE_EMAIL = True
Moreover, I have also tried setting SOCIALACCOUNT_AUTO_SIGNUP = True .


Solution

  • Yes, it seems that I overlooked their documentation or perhaps they recently updated it, the problem was i was using "sign up flow" to sign in an already registered user and thus allauth used to present this signup-form. You can avoid this by writing:
    <a href="{% provider_login_url "facebook" process="login" method="oauth2" %}">login with facebook</a>
    and your sign up link will look like:
    <a href="{% provider_login_url "facebook" method="oauth2" %}">sign up with facebook</a>
    and to connect multiple accounts to same email you'll need to define an adapter like this:

    class SocialLoginAdapter(DefaultSocialAccountAdapter):
        def pre_social_login(self, request, sociallogin):
            # This is tested and should work
            try:
                user = User.objects.get(email=sociallogin.account.user.email)
                sociallogin.connect(request, user)
                # Create a response object
                response = HttpResponse()
                raise ImmediateHttpResponse(response)
            except Exception:
                pass
    

    and do mention this in your settings.py
    SOCIALACCOUNT_ADAPTER = 'path_to_your_adapter_module.SocialLoginAdapter'
    And this is how my final settings.py looked like (allauth part)

    ACCOUNT_AUTHENTICATION_METHOD = "email"
    ACCOUNT_EMAIL_REQUIRED = True
    ACCOUNT_EMAIL_VERIFICATION = "none"  #later change to mandatory
    ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True
    ACCOUNT_UNIQUE_EMAIL = True
    ACCOUNT_USERNAME_REQUIRED = False
    SOCIALACCOUNT_EMAIL_REQUIRED = True
    SOCIALACCOUNT_AUTO_SIGNUP = True
    # custom adapter to override login behavior and associate different social profiles with same email,with same user
    SOCIALACCOUNT_ADAPTER = 'path_to_your_adapter_module.SocialLoginAdapter'