django-rest-framework-passwordless icon indicating copy to clipboard operation
django-rest-framework-passwordless copied to clipboard

PASSWORDLESS_USER_MOBILE_FIELD_NAME on CustomUser

Open InzGIBA opened this issue 5 years ago • 5 comments

If I understand everything correctly, the property "PASSWORDLESS_USER_MOBILE_FIELD_NAME", helps to specify the name of your field

Cannot resolve keyword 'mobile' into field

settings.py:

PASSWORDLESS_AUTH = {
    'PASSWORDLESS_REGISTER_NEW_USERS': False,
    'PASSWORDLESS_USER_MOBILE_FIELD_NAME': 'phone_number',
    'PASSWORDLESS_AUTH_TYPES': ['MOBILE'],
}

models.py:

class CustomUser():
    uuid = models.UUIDField()
    phone_number = models.CharField()

    USERNAME_FIELD = 'phone_number'

InzGIBA avatar Mar 27 '20 01:03 InzGIBA

I faced the same problem.

The issue is that though the PASSWORDLESS_USER_MOBILE_FIELD_NAME allows to provide a custom phone number field; the below code uses the alias_type for querying the User queryset. https://github.com/aaronn/django-rest-framework-passwordless/blob/7fe00dfbef8d163078160c7f317b26ed630fc8cc/drfpasswordless/serializers.py#L47

Since the alias_type variable alternates between 'mobile' or 'email'; we are essentially allowed to use only those two as field names.

@aaronn Please let me know if this is a valid issue and I can potentially raise a pr fixing this.

Thanks!

ankitksr avatar Aug 04 '20 22:08 ankitksr

This what I did and it worked

in your settings.py

'PASSWORDLESS_USER_MOBILE_FIELD_NAME': 'mobile' Screen Shot 2022-02-28 at 1 45 23 PM

In your models.py

Screen Shot 2022-02-28 at 1 44 32 PM

jaymes15 avatar Feb 28 '22 12:02 jaymes15

@ankitksr I don't think it a bug

jaymes15 avatar Feb 28 '22 12:02 jaymes15

@InzGIBA hii, i am also facing same problem. my model has email_id field instated of email. I simply made my serializer and view inherit passwordless serializer and view. and I override alias_type function and i change email to 'email_id' and it worked really fine.

bprachi27 avatar Jul 09 '22 12:07 bprachi27

@ankitksr it is a bug which need to resolve in drfpasswordless .

bprachi27 avatar Jul 09 '22 12:07 bprachi27