update many files

This commit is contained in:
ben
2026-08-03 16:21:10 +02:00
parent 9e69edc08b
commit cff9aa0dd1
5 changed files with 220 additions and 110 deletions
+13 -27
View File
@@ -5,7 +5,10 @@ from datetime import datetime, timedelta
from fastapi import Header, HTTPException
from dotenv import load_dotenv
import os
from fastapi import Depends, HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
security = HTTPBearer()
load_dotenv()
SECRET_KEY = os.getenv("SECRET_KEY")
@@ -64,32 +67,15 @@ def verify_user(username, password):
return None
def get_current_user(authorization: str = Header(None)):
def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security)
):
token = credentials.credentials
if authorization is None:
raise HTTPException(
status_code=401,
detail="Missing token"
)
payload = jwt.decode(
token,
SECRET_KEY,
algorithms=[ALGORITHM]
)
try:
scheme, token = authorization.split(" ")
if scheme.lower() != "bearer":
raise Exception()
payload = jwt.decode(
token,
SECRET_KEY,
algorithms=[ALGORITHM]
)
user_id = payload["user_id"]
return user_id
except JWTError:
raise HTTPException(
status_code=401,
detail="Invalid token"
)
return payload["user_id"]