What method to use to figure out if user is connected to facebook
-
12-11-2019 - |
Question
I am using django-social-auth for facebook login. I am able to login user using "/facebook/login". But, I need to check if user is logged in using facebook on some other page. Is there a method in the module to check if user is logged in using facebook?
thanks
Solution
You can check if the user has any facebook account as such:
for usersocialauth in request.user.usersocialauth_set.all():
print usersocialauth.provider
You might as well get the list of providers for the user:
request.user.usersocialauth_set.values_list('provider')
Beware: a cosmic backward compatibility break was introduced in commit 7f967702. Read answer comment for detail.
OTHER TIPS
Updated for latest Django / python-social-auth
This example checks if facebook is linked to the account. Replace facebook with a valid backend name.
'facebook' in user.social_auth.all().values_list("provider", flat=True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow