May be I should ask that where request.user=Auth...
Are you logging in properly? Test with the DRF UI to see if you can access a view that has permission class to only allow logged in users.
request.user = JWTAuthentication().authenticate(request)[0]
Try code above, if you subclass JWTAuthentication, replace JWTAuthentication with your subclass authentication Class.
request.user = JWTAuthentication().authenticate(request)[0]Try code above, if you subclass JWTAuthentication, replace JWTAuthentication with your subclass authentication Class.
I want to use the authentication by simplejwt directly, not do it again.
But simplejwt to do authentication after the middleware?
I'm not sure.
@zhangxu3486432 What middleware? We include a middleware? You need to paste your settings configuration for SimpleJWT because otherwise I can't understand what's happening. Please also provide steps so that I can also reproduce the error.
@zhangxu3486432 What middleware? We include a middleware? You need to paste your settings configuration for SimpleJWT because otherwise I can't understand what's happening. Please also provide steps so that I can also reproduce the error.
There is a case that we want to get user info in our custom middleware, but django-rest-framework-simplejwt assign user to request after the middleware methods was executed. Thus, JWTAuthentication().authenticate(request) will execute twice.
Most helpful comment
There is a case that we want to get user info in our custom middleware, but
django-rest-framework-simplejwtassign user to request after the middleware methods was executed. Thus, JWTAuthentication().authenticate(request) will execute twice.