I try this code. In my app only authenticate with Github Auth (login with the only github)
account/views.py
from django.shortcuts import render, redirect
from social_django.models import UserSocialAuth
from django.contrib.auth import authenticate, login, logout
def user_login(request):
user=UserSocialAuth.objects.all()
if user.is_authenticated:
login(request,user)
redirect("/")
print("login")
else:
return redirect(request, "registration/login.html")
account/urls.py
from django.urls import path, include
from account import views
from django.contrib.auth import views as auth_views
urlpatterns = [
path("login/", views.user_login, name="login"),
]
I just want to check if the current user is logged in using any Django social auth provider. If logged in user visits the login page then redirect to the index page.