[Django]-AnonymousUser when logged with SimpleJWT

3👍

First you should use self.request.user instead of get_user. The latter assumes session-based authentication and is a function used by the session auth backend to add the user to the request object. Regardless of the auth backend, the middleware takes care of fetching the user for you and adds it to the request object.

Also you’re using JWTTokenUserAuthentication instead of JWTAuthentication. The latter would return you a User object in your request, whereas the former puts a TokenUser in the request.

See this explanation.

Leave a comment