from __future__ import annotations import logging from fastapi import APIRouter, HTTPException from fastapi.responses import JSONResponse from server.auth import create_token, verify_pin from server.schemas import PinLogin router = APIRouter(prefix="/api/auth", tags=["auth"]) logger = logging.getLogger(__name__) NO_STORE = {"Cache-Control": "no-store"} @router.post("/pin") async def auth_pin(payload: PinLogin) -> JSONResponse: if not verify_pin(payload.pin): logger.warning("Failed PIN login attempt") raise HTTPException(status_code=401, detail="Falscher PIN. Dein Gehirn auch.") return JSONResponse({"token": create_token()}, headers=NO_STORE)