File size: 689 Bytes
5caeb47
cf40364
a79668c
315f1c7
90864eb
a79668c
f8b17b7
a79668c
77d31c7
90ff06c
 
 
 
5caeb47
 
a79668c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastapi import Header, HTTPException
from typing import Optional
from app.core.config import get_settings  # keep import, remove module-level call
import logging


def verify_api_key(x_api_key: Optional[str] = Header(default=None)) -> None:
    settings = get_settings()  # ← call inside function
    if not settings.api_key:
        logging.getLogger(__name__).warning(
            "WARNING: API_KEY is not set — all endpoints are publicly accessible. "
            "Set API_KEY in your .env or environment to enable authentication."
        )
        return
    if x_api_key != settings.api_key:
        raise HTTPException(status_code=401, detail="Invalid or missing API key")