I have a class that behaves differently depending on if the user is authenticated or not:
class SomeClass(APIView):
authentication_classes = ()
permission_classes = ()
def get(self, request):
if request.user.is_authenticated:
# do something...
else:
# do something else...
it used to work perfectly with Django 3.2.5 and JSONWebTokenAuthentication. however, I had to upgrade to Django 4.x and TokenAuthentication... with:
authentication_classes = (TokenAuthentication, )
the user is available but the request returns 401 to anonymous users... with:
authentication_classes = ()
anonymous requests are accepted, but I can't see the data of authenticated users.