Django login authentification with "allauth" and "dj_rest_auth" Unable to log in with provided credentials

I'm encountering an issue when trying to POST to http://127.0.0.1:8000/api/auth/login/. The error occurs when I include 'allauth' in my INSTALLED_APPS, but I need it for Google authentication. However, the login works correctly if I don't include 'allauth'.

Any insights on how to resolve this would be greatly appreciated!

this is the response by the api:

{
    "non_field_errors": [
        "Unable to log in with provided credentials."
    ]

}

this is the log from backend

Bad Request: /api/auth/login/

[17/Oct/2024 09:56:13] "POST /api/auth/login/ HTTP/1.1" 400 68

The body of my request:

{
    "email":"test@mail.com",
    "password":"******"
}

urls.py:

from django.contrib import admin
from django.urls import include, path, re_path
from django.conf.urls.static import static
from django.conf import settings
from allauth.account.views import ConfirmEmailView
from accounts.views import GoogleLogin, GoogleLoginCallback


urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('app.urls')),
    path("api/auth/", include("dj_rest_auth.urls")),
    re_path(
        r"^api/auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$",
        ConfirmEmailView.as_view(),
        name="account_confirm_email",
    ),
    path('api/auth/registration/', include('dj_rest_auth.registration.urls')),
    path("api/auth/google/", GoogleLogin.as_view(), name="google_login"),
    path(
        "api/auth/google/callback/",
        GoogleLoginCallback.as_view(),
        name="google_login_callback",
    ),
    
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Setting.py:

AUTH_USER_MODEL = 'app.CustomUser'

MEDIA_URL = '/document/' 
MEDIA_ROOT = BASE_DIR

INSTALLED_APPS = [
    'jazzmin', 

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    'corsheaders',  
    'rest_framework', 
    'rest_framework.authtoken',  
    'rest_framework_simplejwt',
    'allauth', 
    'allauth.account',  
    'allauth.socialaccount', 
    'allauth.socialaccount.providers.google',  
    'dj_rest_auth', 
    'dj_rest_auth.registration',  

    'app',
]

SITE_ID = 1

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(hours=1),
    "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
}

REST_AUTH = {
    "USE_JWT": True,
    "JWT_AUTH_HTTPONLY": False, 
}

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    "allauth.account.middleware.AccountMiddleware",
]


ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "none"

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")

ACCOUNT_EMAIL_VERIFICATION = "mandatory"    
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
LOGIN_URL = "/admin"

GOOGLE_OAUTH_CLIENT_ID = os.getenv("GOOGLE_OAUTH_CLIENT_ID")
GOOGLE_OAUTH_CLIENT_SECRET = os.getenv("GOOGLE_OAUTH_CLIENT_SECRET")
GOOGLE_OAUTH_CALLBACK_URL = os.getenv("GOOGLE_OAUTH_CALLBACK_URL")

SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = True
SOCIALACCOUNT_PROVIDERS = {
    "google": {
        "APPS": [
            {
                "client_id": GOOGLE_OAUTH_CLIENT_ID,
                "secret": GOOGLE_OAUTH_CLIENT_SECRET,
                "key": "",
            },
        ],
        "SCOPE": ["profile", "email"],
        "AUTH_PARAMS": {
            "access_type": "online",
        },
    }
}

I have correctly provided the email and password in the request body.

Вернуться на верх