I recently switched my authentication system to django-allauth
and enabled login via email and password. However, I’ve been encountering persistent issues with manual login, even though both the email (verified) and password are correct. Also, I am currently running django-allauth version 65.7.0.
Note: The user is logged in automatically after signing up, but cannot log in manually after logging out. I can only log in with my superuser username and password in the admin panel.
Below are the updated code from settings.py:
INSTALLED_APPS = [
....
# 3rd party
'crispy_forms',
'crispy_bootstrap5',
'allauth',
'allauth.account',
# local
'accounts',
'pages',
'articles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
....
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
]
AUTHENTICATION_BACKEND = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
ACCOUNT_LOGIN_METHODS = {'email'}
ACCOUNT_SIGNUP_FIELDS = ['first_name', 'last_name', 'username', 'age', 'email*', 'password1*', 'password2*']
AUTH_USER_MODEL = "accounts.CustomUser"
Additionally, I ran the following tests which all passed. So, I am lost as to why I can’t log in manually even with the correct credentials.
from django.test import TestCase
from django.contrib.auth import get_user_model
from django.urls import reverse
class SignupPageTest(TestCase):
email = "testuser@gmail.com"
password = "testpass123"
username = "testuser"
def setUp(self):
url = reverse("account_signup")
self.response = self.client.get(url)
def test_signup_template_is_correct(self):
self.assertEqual(self.response.status_code, 200)
self.assertTemplateUsed(self.response, "account/signup.html")
def test_signup_form_is_correct(self):
new_user = get_user_model().objects.create_user(username=self.username, email=self.email, password=self.password)
self.assertEqual(new_user)
self.assertEqual(get_user_model().objects.all().count(), 1)
self.assertEqual(get_user_model().objects.all()[0].username, self.username)
self.assertEqual(get_user_model().objects.all()[0].email, self.email)
def test_login_successful(self):
login_user = self.client.login(email=self.email, password=self.password)
self.assertEqual(login_user)