auth/ is now an independent package

This commit is contained in:
2026-05-19 22:31:30 +08:00
parent 623fac8749
commit af5f7b38f8
9 changed files with 204 additions and 6 deletions
+19
View File
@@ -0,0 +1,19 @@
from fastapi import Request, HTTPException
import os
from .jwt import decode_token
JWT_SECRET = os.getenv("JWT_SECRET")
JWT_ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256")
def get_current_user(request: Request):
token = request.cookies.get("access_token")
if not token:
raise HTTPException(status_code=401, detail="Not authenticated")
try:
payload = decode_token(token, JWT_SECRET, algorithms=[JWT_ALGORITHM])
return payload["sub"]
except:
raise HTTPException(status_code=401, detail="Invalid token")