0

I'm trying to use login/connect social accounts using dj-rest-auth. I use postman to test api request. I installed according to dj-rest-auth doc. I worked smoothly until I delete a user from user table.

My testing process steps:

  1. dj-rest-auth/login [user 1 credential] -> get correct result [user 1]
  2. delete [user 1] in DB
  3. dj-rest-auth/login [user 1 credential] -> user not found [401 unauthorize]
  4. dj-rest-auth/login [user 2 credential] -> user not found [401 unauthorize] ( user 2 exist in table)
  5. all other api get 401 error (user not found [401 unauthorize])

Do I need to add some setting for this case? I have no idea How deleted user affected to all other api

Please advise me. Thank you.

Saw
  • 21
  • 6

2 Answers2

1

It is solved after I removed (JWT_AUTH_COOKIE = 'auth').

Saw
  • 21
  • 6
0

I think you need to add those settings in settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken', # this
    'dj_rest_auth', # this
    'myapp',
]


REST_USE_JWT = True # this (apply JWT auth)
JWT_AUTH_COOKIE = 'jwt-auth' # this

Check also this settings in project urls.py

from django.contrib import admin
from django.urls import path,include
from django.urls import path

urlpatterns = [
    path("", include("myapp.urls")),
    path('admin/', admin.site.urls),
    path('', include('dj_rest_auth.urls')), # this

]

if still get an error add this

REST_FRAMEWORK = {
    
    'DEFAULT_AUTHENTICATION_CLASSES': (
        
        'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
    )
    
}
  • Thanks for your answer. I added all those code lines, and it still causes the problem. It is solved after I removed (JWT_AUTH_COOKIE = 'auth'). I don't know why that cause error though – Saw Dec 12 '22 at 07:49