Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: session cookie and drf request #16

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
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