diff --git a/allauth_ui/templates/socialaccount/snippets/provider_list.html b/allauth_ui/templates/socialaccount/snippets/provider_list.html index 4bf9131..c79c80c 100644 --- a/allauth_ui/templates/socialaccount/snippets/provider_list.html +++ b/allauth_ui/templates/socialaccount/snippets/provider_list.html @@ -4,13 +4,15 @@ {% get_providers as socialaccount_providers %} {% for provider in socialaccount_providers %} - {% if provider.id == "openid" %} - {% for brand in provider.get_brands %} - {{brand.name}} - {% endfor %} - {% endif %} + {% provider_connected provider user as is_connected %} + {% if not is_connected %} + {% if provider.id == "openid" %} + {% for brand in provider.get_brands %} + {{brand.name}} + {% endfor %} + {% endif %} {{provider.name}} - + {% endif %} {% endfor %} diff --git a/allauth_ui/templatetags/allauth_ui.py b/allauth_ui/templatetags/allauth_ui.py index 0570143..c6d9989 100644 --- a/allauth_ui/templatetags/allauth_ui.py +++ b/allauth_ui/templatetags/allauth_ui.py @@ -1,5 +1,6 @@ import re from pathlib import Path +from allauth.socialaccount.models import SocialAccount from django import template @@ -29,3 +30,13 @@ def socialprovider_color(socialprovider): if name in social_colors: return f"social-{name}" return "bg-stone-900 hover:bg-black" + + +@register.simple_tag +def provider_connected(socialprovider, user): + if not user.is_authenticated: + return False + # pylint: disable=no-member + return bool( + SocialAccount.objects.filter(provider=socialprovider.name.lower(), user=user) + )