I have this code:
from django.contrib.auth import logout, login, authenticate
...
if User.objects.filter(email=email).exists():
existing_user = User.objects.get(email=email)
user = authenticate(username=existing_user.username, password=existing_user.password)
login(request, user)
According to the docs, this should work, but it doesn't, it gives me the error:
request.session[SESSION_KEY] = user._meta.pk.value_to_string(user) AttributeError: 'AnonymousUser' object has no attribute '_meta'
Maybe the problem happens becouse I am using JWT Authentication with Django Rest Framework? It is just an django-powered API, so I guess it is a different scenario, but I don't understand what could be causing the problem.