iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.64k stars 306 forks source link

Login only with email not working #459

Open ifigueroap opened 1 year ago

ifigueroap commented 1 year ago

I'm trying to enable our users to login either with their username or email, but not both. I followed #126 and the username-only login works fine, but the email-only login fails with: "Unable to login with the provided credentials.". This fails both when using email and username_email as the config value of ACCOUNT_AUTHENTICATION_METHOD.

My account-related settings are:

ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_DEFAULT_HTTP_PROTOCOL = env(
    "BACKEND_ACCOUNT_DEFAULT_HTTP_PROTOCOL", default="http"
)
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_UNIQUE_EMAIL = True

# Allows users to login either
# by username or email.
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
davidyytan commented 1 year ago

hi looking for this fix as well. my settings file cant run with

ACCOUNT_USER_MODEL_USERNAME_FIELD = None

It throws an error when migrating.

cerek commented 1 year ago

Hi @ifigueroap , hopefully this issue had been solved. If not, I hope this can help you.

I encounter the same issue when I enable users to login with their username and email via setup the ACCOUNT_AUTHENTICATION_METHOD = "username_email".

After that, I try to do some research for this issue, finally, I fixed it by adding parameters to setting.py, like below:

ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]

Appreciate.

sowinski commented 1 year ago

Anything new about this?