Multiple Login Field Options for Django Rest Framework (JWT)

500 Views Asked by At

How can I override the django-rest-framework-jwt JSONWebTokenSerializer to allow for a user to login via either email, username or password.

I see that as the suggested option in this github issue but am not sure how I'd override the default JSONWebTokenSerializer as its not among the JWT_AUTH settings.

I want to be able to provide functionality as seen in this SO question where you can allow a Django User to login via any field you may have in the Custom user table

1

There are 1 best solutions below

0
On

For anyone using Django Allauth, adding these settings in the settings.py file solves this.

ACCOUNT_AUTHENTICATION_METHOD=“username_email” 
ACCOUNT_EMAIL_REQUIRED = True 
ACCOUNT_UNIQUE_EMAIL = True 
ACCOUNT_USERNAME_REQUIRED = True

All the configurations can be found here.