Skip to content

Commit

Permalink
fix: session cookie and drf request
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Oct 5, 2023
1 parent a67b821 commit b0583b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions codeforlife/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.auth.models import AnonymousUser
from django.core.handlers.wsgi import WSGIRequest as _WSGIRequest
from django.http import HttpRequest as _HttpRequest
from rest_framework.request import Request as _Request

from .user.models import User
from .user.models.session import SessionStore
Expand All @@ -16,3 +17,8 @@ class WSGIRequest(_WSGIRequest):
class HttpRequest(_HttpRequest):
session: SessionStore
user: t.Union[User, AnonymousUser]


class Request(_Request):
session: SessionStore
user: t.Union[User, AnonymousUser]
4 changes: 3 additions & 1 deletion codeforlife/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
# https://docs.djangoproject.com/en/3.2/topics/http/sessions/

SESSION_ENGINE = "codeforlife.user.models.session"
SESSION_COOKIE_AGE = 60 * 60
SESSION_SAVE_EVERY_REQUEST = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_NAME = "sessionid_httponly_true"
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_AGE = 60 * 60
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "None"
SESSION_COOKIE_DOMAIN = "localhost" if DEBUG else "codeforlife.education"
Expand Down

0 comments on commit b0583b4

Please sign in to comment.