How to use email for login in django rest?
this is my serializer for login view when I'm trying to use email for login it returns None (it can't take users' email)! but with the username, everything is ok anyone can help me to find what is the problem?
class LoginSerializer(serializers.Serializer):
email = serializers.EmailField()
password = serializers.CharField()
def validate(self, data):
user_email = authenticate(**data)
print(user_email)
print('this is serializer print')
if user_email and user_email.is_active:
return user_email
raise serializers.ValidationError("Incorrect Credentials")
this is my login view
class LoginAPI(generics.GenericAPIView):
serializer_class = LoginSerializer
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
print(serializer)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data
print(user)
return Response({
"user": UserSerializer(user, context=self.get_serializer_context()).data,
"token": AuthToken.objects.create(user)[1]
})