Django drf simple-jwt authentication“detail”: “No active account found with the given credentials”

前端 未结 5 973
独厮守ぢ
独厮守ぢ 2021-01-18 00:28

I am implementing user authentication with django-rest_framework_simple-jwt with custom user, My models.py:

class UserManager(BaseUserManager):
    def crea         


        
相关标签:
5条回答
  • 2021-01-18 00:57

    Either you did not create a superuser for your Django application or you are provided the wrong credentials for authentication

    0 讨论(0)
  • 2021-01-18 00:59

    Did you remember to set in settings:

    AUTH_USER_MODEL = 'your_app_name.User'
    
    0 讨论(0)
  • 2021-01-18 01:01

    Ensure your password is being hashed before it is stored in your db. I ran into the same problem and discovered my passwords were being stored in plain text. Adding the following to my UserSerializer solved the issue

    from django.contrib.auth.hashers import make_password
    
    def validate_password(self, value: str) -> str:
        """
        Hash value passed by user.
    
        :param value: password of a user
        :return: a hashed version of the password
        """
        return make_password(value)
    
    0 讨论(0)
  • 2021-01-18 01:05

    You should create new superuser account after setting up JWT authentication

    then use that account to get the token

    python manage.py createsuperuser
    
    0 讨论(0)
  • 2021-01-18 01:10

    It seems my error was being caused by a write_only parameter on my password field

    class RegisterSerializer(serializers.ModelSerializer):
        password = serializers.CharField(
            max_length=68, min_length=6, write_only=True)
    
    
        class Meta:
            model = User
            fields = ['email', 'username', 'password']
    

    Removed it:

    class RegisterSerializer(serializers.ModelSerializer):
        password = serializers.CharField(
            max_length=68, min_length=6)
    
    
        class Meta:
            model = User
            fields = ['email', 'username', 'password']
    

    and then it was all sunshine and rainbows after that :-)

    0 讨论(0)
提交回复
热议问题