eadwinCode/django-ninja-jwt

Add documentation for customizing the fields for authentication

LucasCTN opened this issue · 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 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.

@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.