简体   繁体   中英

Next query parameter doesn't work with django allauth for facebook login

I have implemented User account management into my application using Django all-auth. I have enabled login using username and password as well as with facebook connect.

The problem goes like this:

1) User visits a page http://example.com/page1/ and clicks login

2) He's taken to http://example.com/accounts/login?next=/page1/

3) When the user logs in using username and password, the user is redirected back to http://example.com/page1 . But if the user logs in with facebook, he's taken to homepage.

How can I get desired behavior with Facebook login too?

You need to override the get_login_redirect_url method of django-allauth.

For this inherit the DefaultAccountAdapter class as

from allauth.account.adapter import DefaultAccountAdapter

class MyAccountAdapter(DefaultAccountAdapter):
    def get_login_redirect_url(self, request):
        # get the next parameter from request object and return the url 

And make changes on settings.py

ADAPTER = "APPNAME.FILENAME.MyAccountAdapter"
ACCOUNT_ADAPTER = "APPNAME.FILENAME.MyAccountAdapter"

This should work !

How are you generating the Facebook login link? Most likely you are not indicating the next parameter there. The allauth documentation gives this example:

<a href="{% provider_login_url "openid" openid="..." next="/success/url/" %}">Google</a>

To get the proper next parameter you can access request.GET.next .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM