File size: 578 Bytes
9215c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
from fastapi import Header, HTTPException, status
from dotenv import load_dotenv

load_dotenv()

def admin_auth(x_admin_key: str = Header(...)):
    """
    Simple admin authentication using a shared secret key.
    Used ONLY for admin routes (POST / PUT / DELETE).
    """
    admin_key = os.getenv("ADMIN_API_KEY")

    if not admin_key:
        raise RuntimeError("ADMIN_API_KEY not set in environment")

    if x_admin_key != admin_key:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Unauthorized"
        )