djangoとreactを使ってjwt認証は以下のサイトがわかりやすいです。
https://medium.com/@dakota.lillie/django-react-jwt-authentication-5015ee00ef9a今回は、その実装時につまったところのメモです。
実装についてのメモ
参考文献のmysite/settings.pyは以下のようにすると動きました。
# 省略
INSTALLED_APPS = [
# 省略
'rest_framework', # new
'corsheaders', # new
'core.apps.CoreConfig', # new
]
MIDDLEWARE = [
# ...
'corsheaders.middleware.CorsMiddleware', # new
]
# new
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
# new
CORS_ORIGIN_WHITELIST = [
'http://localhost:3000',
'http://localhost:8000',
'http://localhost:8080',
]
# new
JWT_AUTH = {
'JWT_RESPONSE_PAYLOAD_HANDLER': 'mysite.utils.my_jwt_response_handler'
}

