Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion myapp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@

@api.exception_handler(AuthenticationError)
def custom_authentication_error_handler(request, exc):
if "Token is invalid or expired" in str(exc):
return api.create_response(
request,
{"message": "Your session has expired. Please log in again."},
status=401,
)
return api.create_response(
request,
{"message": "Please log in to access this resource."},
{"message": "Authentication failed. Please log in again."},
status=401,
)

Expand Down
40 changes: 25 additions & 15 deletions myapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"articles",
"posts",
"storages",
"rest_framework_simplejwt.token_blacklist",
]

AUTH_USER_MODEL = "users.User"
Expand All @@ -60,10 +61,12 @@
}

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=180),
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=15),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
"ROTATE_REFRESH_TOKENS": True,
"BLACKLIST_AFTER_ROTATION": True,
"ALGORITHM": "HS256",
"SIGNING_KEY": config("JWT_SECRET_KEY", default=SECRET_KEY),
}

MIDDLEWARE = [
Expand All @@ -82,20 +85,29 @@

CORS_ALLOW_ALL_ORIGINS = True

# # Allow headers
# CORS_ALLOW_HEADERS = [
# "accept",
# "accept-encoding",
# "Authorization",
# "content-type",
# "dnt",
# "origin",
# "user-agent",
# "x-csrftoken",
# "x-requested-with",
# "set-cookie",
# CORS_ALLOW_ORIGINS = [
# "http://localhost:3000",
# ]


CORS_ALLOW_CREDENTIALS = True

CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
]

CORS_EXPOSE_HEADERS = ['content-type', 'set-cookie']

COOKIE_DOMAIN = config("COOKIE_DOMAIN", default="localhost")

ROOT_URLCONF = "myapp.urls"

TEMPLATES = [
Expand Down Expand Up @@ -132,7 +144,6 @@
}

if not DEBUG:
print(config("DATABASE_URL"))
DATABASES["default"] = dj_database_url.parse(config("DATABASE_URL"))


Expand Down Expand Up @@ -219,7 +230,6 @@
# Celery Configurations
CELERY_BROKER_URL = config("CELERY_BROKER_URL", default="redis://localhost:6379/0")
CELERY_RESULT_BACKEND = config("CELERY_RESULT_BACKEND", default="redis://localhost:6379/0")
print("redis: ", CELERY_BROKER_URL, CELERY_RESULT_BACKEND)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
Expand Down
Loading