A simpler way of achieving this will be via using the rest_framework_simplejwt
package. I believe you've also used the same package for JWT generation as well.
While the user is performing logout, you need to clear the cache from the frontend, and also need to add the refresh token to a blacklist in the backend.
Access tokens are short-lived and do not need to be blacklisted, it is preferred to have minimal lifespan for the access tokens. So that they will eventually expire.
rest_framework_simplejwt.token_blacklist
will only blacklist the refresh tokens by default.
All you need to do is add the following app on your settings.py INSTALLED_APPS.
INSTALLED_APPS = (
'rest_framework_simplejwt.token_blacklist',
)
And also configure the urls.py for the TokenBlacklistView
from rest_framework_simplejwt.views import TokenBlacklistView
urlpatterns = [
...
path('logout/', TokenBlacklistView.as_view(), name='token_blacklist'),
...
]
Source:
https://django-rest-framework-simplejwt.readthedocs.io/en/latest/blacklist_app.html