from fastapi import APIRouter, Depends, Response from sqlalchemy.orm import Session from app.core.config import Settings from app.domain.auth import create_session, revoke_session from app.endpoints.dependencies import ( get_basic_credentials, get_bearer_token, get_db, get_settings, ) from app.schemas.session import AuthSession router = APIRouter(prefix="/api/v1/auth", tags=["auth"]) @router.post("/sessions", status_code=201) def login( credentials: tuple[str, str] = Depends(get_basic_credentials), session: Session = Depends(get_db), settings: Settings = Depends(get_settings), ) -> AuthSession: username, password = credentials return create_session(session, username, password, settings.session_ttl_seconds) @router.delete("/sessions/current", status_code=204) def logout( token: str = Depends(get_bearer_token), session: Session = Depends(get_db), ) -> Response: revoke_session(session, token) return Response(status_code=204)