aaronn / django-rest-framework-passwordless

Passwordless Auth for Django REST Framework
MIT License
708 stars 154 forks source link

UNIQUE constraint failed: auth_user.username #116

Closed peidrao closed 2 years ago

peidrao commented 2 years ago

When trying to make a request to /auth/email/, and with PASSWORDLESS_REGISTER_NEW_USERS = True, the user is not created and the title error is returned.

if api_settings.PASSWORDLESS_REGISTER_NEW_USERS is True:
    # If new aliases should register new users.
    try:
        user = User.objects.get(**{self.alias_type+'__iexact': alias})
    except User.DoesNotExist:
        # alias is empty
        user = User.objects.create(**{self.alias_type: alias})
        user.set_unusable_password()
        user.save()

Request

{
    "email": "asd@gmail.com"
}