cloudairambo / routers /admin_auth.py
rihancloud's picture
Deploy clean FastAPI backend without node_modules
99fdb5f
Raw History Blame Contribute Delete
666 Bytes
# routers/admin_auth.py
from fastapi import APIRouter, HTTPException, Form
import jwt
from datetime import datetime, timedelta
from core.config import settings
router = APIRouter()
# IMPORTANT: Do NOT use /admin/login (reserved by starlette-admin)
@router.post("/api/admin/login")
def admin_login(password: str = Form(...)):
if password != settings.ADMIN_SECRET:
raise HTTPException(status_code=401, detail="Invalid password")
token = jwt.encode(
{
"role": "admin",
"exp": datetime.utcnow() + timedelta(days=1)
},
settings.ADMIN_SECRET,
algorithm="HS256"
)
return {"token": token}