0
votes

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.

2

2 Answers

1
votes

Please post other relevant codes like urls.py. Anyways you should simply redirect to index

return redirect("index")

and in urls.py

path('',views.index,name = "index"),
0
votes

why not try to install "social-auth-app-django" for the social-authentication.

check the site below for more details

https://python-social-auth.readthedocs.io/en/latest/configuration/django.html