Django Rest Framework Panel - login and logout not working with Simple JWT

Viewed 968

I am creating a backend api with DRF. I created a custom user model, I am using allauth and dj-rest-auth for authentication. So far so good, I also added this path to my urls so that the DRF panel allows me to login and logout:

path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

The problem happens when I also add Simple JWT. The login/logout function doesn't work anymore, I can perform authentication only through dj-rest-auth paths.

urlpatterns = [
    ...,
    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls'))
]

Does anybody know if it is possible to also have DRF header perform logout/login? The error that I get is this, even after providing the correct credentials:

HTTP 401 Unauthorized
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
WWW-Authenticate: Bearer realm="api"

{
    "detail": "Authentication credentials were not provided."
}
1 Answers

Did you add the following code to settings.py?

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