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")