Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django allauth Redirect after social signup

I would like to redirect to a certain link after social signup, how and where do I do that? I can do it for regular signup but I can't for social signup.

like image 620
Ebtessam Zoheir Avatar asked Jan 03 '15 20:01

Ebtessam Zoheir


2 Answers

Alternatively you can write your own custom social account adapter to handle different logged in redirection from different social accounts and not messing with your normal account settings, like so:

# adapter.py    
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class SocialAccountAdapter(DefaultSocialAccountAdapter):
    def get_login_redirect_url(self, request):
        # do your logic here for different social accounts
        ...
        return 'url/to/your/redirection' # or reverse(view) or whatever

# settings.py
SOCIALACCOUNT_ADAPTER = "point.to.adaptor.SocialAccountAdapter"

Edited:

In case you want to alter the redirection for newly signed up, you may customise adapter's save_user method:

class SocialAccountAdapter(DefaultSocialAccountAdapter):
    ...
    def save_user(self, request, sociallogin, form=None):
        super(DefaultSocialAccountAdapter, self).save_user(request, sociallogin, form=form)
        # your logic here... and return redirection afterward
        return redirect(...)
like image 126
Anzel Avatar answered Sep 30 '22 17:09

Anzel


After both social and normal it should be redirecting to your LOGIN_REDIRECT_URL in settings. Do you have that set?

Theres also some good information here about custom redirection

like image 25
awwester Avatar answered Sep 30 '22 17:09

awwester