Spaces:
Sleeping
Sleeping
Commit
·
d4a51a1
1
Parent(s):
f5e2ee2
debug validation
Browse files- main.py +5 -3
- requirements.txt +2 -1
main.py
CHANGED
|
@@ -3,6 +3,7 @@ from fastapi import FastAPI, HTTPException, Header, status, APIRouter
|
|
| 3 |
from pydantic import BaseModel, EmailStr
|
| 4 |
from typing import Dict, List
|
| 5 |
from datetime import datetime, timedelta, timezone
|
|
|
|
| 6 |
import secrets
|
| 7 |
import hashlib
|
| 8 |
import uuid
|
|
@@ -172,7 +173,8 @@ async def init_system_user():
|
|
| 172 |
print("System user already exists, continuing...")
|
| 173 |
else:
|
| 174 |
raise e
|
| 175 |
-
|
|
|
|
| 176 |
async def validate_session(user_id: str, token: str, user_agent: str) -> Optional[dict]:
|
| 177 |
"""
|
| 178 |
Validates the session for the given user_id, token, and user_agent.
|
|
@@ -209,8 +211,8 @@ async def validate_session(user_id: str, token: str, user_agent: str) -> Optiona
|
|
| 209 |
# Get the current time (UTC) with timezone awareness
|
| 210 |
current_time = datetime.now(timezone.utc)
|
| 211 |
|
| 212 |
-
# Parse the 'expires' field from the session
|
| 213 |
-
session_expiry =
|
| 214 |
|
| 215 |
# Check if the token has expired
|
| 216 |
if session_expiry <= current_time:
|
|
|
|
| 3 |
from pydantic import BaseModel, EmailStr
|
| 4 |
from typing import Dict, List
|
| 5 |
from datetime import datetime, timedelta, timezone
|
| 6 |
+
from dateutil import parser
|
| 7 |
import secrets
|
| 8 |
import hashlib
|
| 9 |
import uuid
|
|
|
|
| 173 |
print("System user already exists, continuing...")
|
| 174 |
else:
|
| 175 |
raise e
|
| 176 |
+
|
| 177 |
+
|
| 178 |
async def validate_session(user_id: str, token: str, user_agent: str) -> Optional[dict]:
|
| 179 |
"""
|
| 180 |
Validates the session for the given user_id, token, and user_agent.
|
|
|
|
| 211 |
# Get the current time (UTC) with timezone awareness
|
| 212 |
current_time = datetime.now(timezone.utc)
|
| 213 |
|
| 214 |
+
# Parse the 'expires' field from the session using dateutil.parser
|
| 215 |
+
session_expiry = parser.parse(session["expires"])
|
| 216 |
|
| 217 |
# Check if the token has expired
|
| 218 |
if session_expiry <= current_time:
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ pydantic[email]
|
|
| 3 |
user-agents
|
| 4 |
python-dotenv
|
| 5 |
uvicorn[standard]
|
| 6 |
-
supabase
|
|
|
|
|
|
| 3 |
user-agents
|
| 4 |
python-dotenv
|
| 5 |
uvicorn[standard]
|
| 6 |
+
supabase
|
| 7 |
+
python-dateutil
|