title: How to solve error 401 unauthorized login in DRF simple jwt user login
body: <p>I am creating DRF authentication APIs for Abstract Base users in my Django project and using simple JWT. The registration and email verification APIs work fine, but when I try to log in using the credentials of a valid user, I get an error 401 unauthorized access.</p>
  <p>the custom user model in <code>models.py</code></p>
  <pre class="lang-py prettyprint-override"><code>class User(AbstractBaseUser, PermissionsMixin):
      username = models.CharField(max_length=255, unique=True,db_index=True)
      email = models.EmailField(max_length=255, unique=True,db_index=True)
      is_verified = models.BooleanField(default=False)
      is_active = models.BooleanField(default=False)
      is_staff = models.BooleanField(default=False)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now_add=True)
  
      USERNAME_FIELD = 'email'
      REQUIRED_FIELD = ['username']
  
      objects = UserManager()
  
      def __str__(self):
          return self.email
  
      def tokens(self):
          refresh = RefreshToken.for_user(self)
          return{
              'refresh':str(refresh),
              'access': str(refresh.access_token)
          }
  </code></pre>
  <p>Here are my <code>login</code> and <code>verification</code> views:</p>
  <pre class="lang-py prettyprint-override"><code>
  class VerifyEmail(views.APIView):
      serializer_class = EmailVerificationSerializer
  
      token_param_config = openapi.Parameter('token',in_=openapi.IN_QUERY, description='Description', type=openapi.TYPE_STRING)
  
      @swagger_auto_schema(manual_parameters=[token_param_config])
      def get(self, request):
          token = request.GET.get('token')
          try:
              payload = jwt.decode(token,settings.SECRET_KEY, algorithms=['HS256'])
              user = User.objects.get(id=payload['user_id'])
              if not user.is_verified:
                  user.is_verified = True
                  user.save()
              return Response({'email': 'Succesfully activated'}, status = status.HTTP_200_OK)
  
          except jwt.ExpiredSignatureError as identifier:
              return Response({'error': 'Activation Expired'}, status= status.HTTP_400_BAD_REQUEST)
          except jwt.exceptions.DecodeError as identifier:
              return Response({'error': 'Invalid token'}, status=status.HTTP_400_BAD_REQUEST)
              
  class LoginAPIView(generics.GenericAPIView):
      serializer_class = LoginSerializer
      def post(self, request):
          serializer = self.serializer_class(data=request.data)
          serializer.is_valid(raise_exception=True)
  
          return Response(serializer.data, status=status.HTTP_200_OK)
  </code></pre>
  <p>Here is my <code>login</code> serializer:</p>
  <pre class="lang-py prettyprint-override"><code>class LoginSerializer(serializers.ModelSerializer):
      email = serializers.EmailField(max_length=255, min_length=3)
      password = serializers.CharField(max_length=68, min_length=8, write_only=True)
      username = serializers.CharField(max_length=255, min_length=3, read_only = True)
      tokens = serializers.CharField(max_length=68, min_length=8, read_only = True)
  
  
      class Meta:
          model = User
          fields = ['email', 'password', 'username', 'tokens']
  
  
      def validate(self, attrs):
          email = attrs.get('email', '')
          password = attrs.get('password', '')
    
          user = auth.authenticate(email=email, password=password)
  
          if not user:
              raise AuthenticationFailed('Invalid Credentials, try again!')
          if not user.is_active:
              raise AuthenticationFailed('Acccount disabled, please contact admin')
          if not user.is_verified:
              raise AuthenticationFailed('Email is not verified')
                  
          return {
              'email': user.email,
              'username': user.username,
              'tokens': user.tokens
          }
          
          return super().validate(attrs)
  
  </code></pre>
  <p>So the error raised is &quot;Invalid credentials&quot; meaning that details of the user don't exist, while the users are actually there when I check the database.
  <a href="https://i.stack.imgur.com/wn5kc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wn5kc.png" alt="enter image description here" /></a></p>
  <p>Anyone, please help.</p>