Django allauth redirect after social registration

I would like to redirect to a specific link after social registration, how and where do I do it? I can do this for regular registration, but I can not for social registration.

+5
source share
2 answers

Alternatively, you can write your own social account adapter to handle various logged redirects from different social accounts and not bother with your usual account settings, like this:

# 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 by:

If you want to change the redirection for a newly registered, you can configure the 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(...) 
+3
source

Once social and normal, it should be redirected to your LOGIN_REDIRECT_URL in settings. Do you have this kit?

There is also good info here about user redirects.

+1
source

Source: https://habr.com/ru/post/1210326/


All Articles