I am trying to implement an email authentication with djangorestframework, dj-rest-auth and allauth.
Here is my custom user model
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(_("email address"), unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
objects = CustomUserManager()
def __str__(self):
return self.email
Here is my settings.py
...
AUTH_USER_MODEL = "users.CustomUser"
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_LOGIN_METHODS = {'email'}
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
...
It registers a new user as expected if the there is not an existing user with the same email, but if I try to create an user with an email that has already been registered, I got this error:
django.db.utils.IntegrityError: UNIQUE constraint failed: users_customuser.email
I expected allauth to handle this error since it does with username authentication. Am I missing something? Should I handle this error manually?