check if the user has logged in with social account - Django

Viewed 794

in the web site that i'm working on , I have an authetication system and I'm using django allauth at the same time so the user can login with his gmail or facebook account if he wants . how can I check in the template if the user has logged in with his facebook/gmail account ? i want somthing like this

{% if user not 'use his facebook or gmail'  %}                     
    <a href="{% some url %}">
       <button type="button" class="btn btn-primary" data-dismiss="modal">somthing </button>
      </a> 
{% endif %}
2 Answers

i've found this and it has done what I needed

 {% load socialaccount %}
    
  {% get_social_accounts user as accounts %}
  {% if accounts %} "if the user has logged in using his facebook account or his google account"

          "do somthing here"
        
  {% endif %}

for more details check the documentation of django-allauth

for future readers, in view.py you do can something like this to detect if user is a social user or not

is_social = user.socialaccount_set.exists()

it returns True if your logged in with facebook/google/... else it return False

Related