From ed8de169de1ae0f09e4d9adff0e30bb287e5780e Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Wed, 28 Jan 2026 02:22:47 +0000 Subject: [PATCH] Credential update was being done out of transaction, now part of login. --- paskia/db/operations.py | 13 +++++++------ paskia/fastapi/remote.py | 6 ++++-- paskia/fastapi/ws.py | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/paskia/db/operations.py b/paskia/db/operations.py index 43f438c..3c61103 100644 --- a/paskia/db/operations.py +++ b/paskia/db/operations.py @@ -707,7 +707,8 @@ def _create_token() -> str: def login( user_uuid: UUID, - credential: Credential, + credential_uuid: UUID, + sign_count: int, host: str, ip: str, user_agent: str, @@ -728,8 +729,8 @@ def login( now = datetime.now(timezone.utc) if user_uuid not in _db.users: raise ValueError(f"User {user_uuid} not found") - if credential.uuid not in _db.credentials: - raise ValueError(f"Credential {credential.uuid} not found") + if credential_uuid not in _db.credentials: + raise ValueError(f"Credential {credential_uuid} not found") session_key = _create_token() user_str = str(user_uuid) @@ -738,12 +739,12 @@ def login( _db.users[user_uuid].last_seen = now _db.users[user_uuid].visits += 1 # Update credential - _db.credentials[credential.uuid].sign_count = credential.sign_count - _db.credentials[credential.uuid].last_used = now + _db.credentials[credential_uuid].sign_count = sign_count + _db.credentials[credential_uuid].last_used = now # Create session _db.sessions[session_key] = Session( user=user_uuid, - credential=credential.uuid, + credential=credential_uuid, host=host, ip=ip, user_agent=user_agent, diff --git a/paskia/fastapi/remote.py b/paskia/fastapi/remote.py index 01c5758..baa2d63 100644 --- a/paskia/fastapi/remote.py +++ b/paskia/fastapi/remote.py @@ -334,7 +334,8 @@ async def websocket_remote_auth_permit(ws: WebSocket): normalized_host = hostutil.normalize_host(request.host) session_token = db.login( user_uuid=cred.user, - credential=cred, + credential_uuid=cred.uuid, + sign_count=cred.sign_count, host=normalized_host, ip=request.ip, user_agent=request.user_agent, @@ -346,7 +347,8 @@ async def websocket_remote_auth_permit(ws: WebSocket): normalized_host = hostutil.normalize_host(request.host) session_token = db.login( user_uuid=cred.user, - credential=cred, + credential_uuid=cred.uuid, + sign_count=cred.sign_count, host=normalized_host, ip=request.ip, user_agent=request.user_agent, diff --git a/paskia/fastapi/ws.py b/paskia/fastapi/ws.py index 5e80ee5..2f01b8b 100644 --- a/paskia/fastapi/ws.py +++ b/paskia/fastapi/ws.py @@ -115,7 +115,8 @@ async def websocket_authenticate(ws: WebSocket, auth=AUTH_COOKIE): token = db.login( user_uuid=cred.user, - credential=cred, + credential_uuid=cred.uuid, + sign_count=cred.sign_count, host=normalized_host, ip=metadata["ip"], user_agent=metadata["user_agent"],