Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sends user_logged_in twice #377

Open
AGM-90 opened this issue Feb 4, 2025 · 1 comment
Open

Sends user_logged_in twice #377

AGM-90 opened this issue Feb 4, 2025 · 1 comment

Comments

@AGM-90
Copy link

AGM-90 commented Feb 4, 2025

Sends user_logged_in twice when we overide LoginView

from django.contrib.auth import login

from rest_framework import permissions
from rest_framework.authtoken.serializers import AuthTokenSerializer
from knox.views import LoginView as KnoxLoginView

class LoginView(KnoxLoginView):
permission_classes = (permissions.AllowAny,)

def post(self, request, format=None):
    serializer = AuthTokenSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    user = serializer.validated_data['user']
    login(request, user)
    return super(LoginView, self).post(request, format=None)
@ooppsss60
Copy link

Most likely, the signal is sent in the method login(request, user) and super(LoginView, self).post(request, format=None). Try to replace login(request, user) with request.user = user, but that will turn off Django Session Auth (
which is not critical if you use Knox-token authentication).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants