from fastapi import APIRouter, Depends, Header, Request from auth import get_current_user from models import User import time import jwt from config import SECRET_KEY, ALGORITHM router = APIRouter() @router.get("/health") async def health_check(): """ Check if the API is running """ return {"status": "healthy"} @router.get("/auth-check") async def auth_check(current_user: User = Depends(get_current_user)): """ Debug endpoint to verify authentication is working """ return { "authenticated": True, "username": current_user.username, "message": "Authentication successful", } @router.get("/debug-auth") async def debug_auth(request: Request, authorization: str = Header(None)): """ Debug endpoint to manually inspect the authorization header and token """ headers = dict(request.headers) auth_header = headers.get("authorization", "Not found") token_info = {"valid": False, "error": None, "payload": None} if authorization and authorization.startswith("Bearer "): token = authorization.replace("Bearer ", "") try: payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) token_info["valid"] = True token_info["payload"] = payload except Exception as e: token_info["error"] = str(e) return { "headers": headers, "auth_header": auth_header, "token_info": token_info, "host_info": { "url": str(request.url), "base_url": str(request.base_url), "method": request.method, }, }