djangofacebookdisconnectsocial-auth-app-django

social-auth-app-django: how to disconnect a user without password


On my site (www.raptors.ru) I'm using social-auth-app-django to authorize users from Facebook. To make their logging in easier I made following setting:

ACCOUNT_PASSWORD_INPUT_RENDER_VALUE = True

so that users do not need to enter their password. When the FB user logs in the first time, a record is created in the table users. What is important, this user has no password on my site. However, this user is fully functional: he is able to publish posts, make comments, etc. The problems begin if the user wants to disconnect from his social account. First, if one tries to disconnect his account via the LoginCancelledView (direct link is https://raptors.ru/accounts/social/login/cancelled/, he gets a message that he successfully disconnected, but it's not truth since his username is still on the page header (see the the screenshot).

Wrong success message (the user is still connected and logged in

Second way to disconnect is from the connections page (https://raptors.ru/accounts/social/connections/).

Connections page

However, if the user clicks the Remove button, Django doesn't do it and report following error: Your account has no password set up.

The error report

Please tell me, which is the correct and working way to disconnect (or completely remove) the Facebook user from my site? FB insists that I should provide this option.


Solution

  • There is a logout (django.contrib.auth) method which can be used for this, for e.g. in my views.py:

    from django.contrib.auth import logout
    from django.shortcuts import redirect
    ...
    def logout_request(request)
        logout(request)
        return redirect('/')
    

    and in my urls.py, to trigger this method:

    urlpatterns =[
        ...,
        path('logout', views.logout_request, name="logout),
    
    ]
    

    and this works for me