Spaces:
Runtime error
Runtime error
File size: 666 Bytes
99fdb5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # 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}
|