django-ninja-jwt icon indicating copy to clipboard operation
django-ninja-jwt copied to clipboard

Add documentation for customizing the fields for authentication

Open LucasCTN opened this issue 2 years ago • 2 comments

I'm having a hard time trying to change the username field to become email, and use it for validation instead. It would be useful to have a tutorial for making modifications like these in the docs.

I thought it would be on customizing_token_claims.md, but it just adds the field without validating it, and username is still required.

LucasCTN avatar Oct 31 '23 23:10 LucasCTN

@LucasCTN I think you need customize your User model like descibe at django documentation: https://docs.djangoproject.com/en/4.2/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

for example:

class MyUser(AbstractBaseUser):
    email = models.EmailField(_("email address"), max_length=255, unique=True)
     ...
    USERNAME_FIELD = "email"

Maybe I'm wrong but I think it's not a customization from django ninja jwt but of django.

pedrohsbarbosa99 avatar Nov 01 '23 00:11 pedrohsbarbosa99

@LucasCTN I think you need customize your User model like descibe at django documentation: https://docs.djangoproject.com/en/4.2/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

for example:

class MyUser(AbstractBaseUser):
    email = models.EmailField(_("email address"), max_length=255, unique=True)
     ...
    USERNAME_FIELD = "email"

Maybe I'm wrong but I think it's not a customization from django ninja jwt but of django.

Oh, you are right! My apologies, I presumed I would need to customize the authentication.

LucasCTN avatar Nov 01 '23 02:11 LucasCTN