Currently I started a project to learn more of django + jwt and react.
Instead of using sql
I used mongodb
with django
instead by using djongo
.
It works pretty well setting things up, creating new model to test out. So I started looking for django + jwt
tutorials and come upon this tutorial
https://hackernoon.com/110percent-complete-jwt-authentication-with-django-and-react-2020-iejq34ta
Everything works fine up until the end about blacklisting tokens
I have my settings.py
as suggested
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=14),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': True,
'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUTH_HEADER_TYPES': ('JWT',),
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',
}
by making the BLACKLIST_AFTER_ROTATION
to True
, I need to do a migration by python manage.py migrate
This is where the error happens, error I got is
djongo.sql2mongo.SQLDecodeError: FAILED SQL: CREATE TABLE "token_blacklist_blacklistedtoken" ("id" int32 NOT NULL PRIMARY KEY AUTOINCREMENT, "blacklisted_at" date NOT NULL)
I was poking around and couldn't get a solution so I tried changing db back using mysql
instead, then the migration worked like a charm.
Does anyone know if I do keep using mongodb
instead of mysql
, is there a workaround for this migration and functionality to work?
Thanks in advance for any advices.