[fix] fix multiple sessions

Session is created with user.id now instead of full user. Old sessions
dont will destroy.
This commit is contained in:
Tim Gröger 2024-10-10 13:29:05 +02:00
parent 0570a9a32f
commit 81080404fb
1 changed files with 4 additions and 5 deletions

View File

@ -1,13 +1,12 @@
import secrets import secrets
from datetime import datetime, timezone from datetime import datetime, timezone
from werkzeug.exceptions import Forbidden, Unauthorized
from ua_parser import user_agent_parser from ua_parser import user_agent_parser
from werkzeug.exceptions import Forbidden, Unauthorized
from .. import logger from .. import logger
from ..models import Session
from ..database import db from ..database import db
from ..models import Session
lifetime = 1800 lifetime = 1800
@ -72,7 +71,7 @@ def create(user, request_headers=None) -> Session:
logger.debug(f"platform: {user_agent['os']['family']}, browser: {user_agent['user_agent']['family']}") logger.debug(f"platform: {user_agent['os']['family']}, browser: {user_agent['user_agent']['family']}")
session = Session( session = Session(
token=token_str, token=token_str,
user_=user, _user_id=user.id_,
lifetime=lifetime, lifetime=lifetime,
platform=user_agent["os"]["family"], platform=user_agent["os"]["family"],
browser=user_agent["user_agent"]["family"], browser=user_agent["user_agent"]["family"],