2026-07-04 20:09:54 +02:00
|
|
|
"""Auth endpoints: login, logout."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from auth import login, logout, require_auth
|
|
|
|
|
from fastapi import APIRouter, Depends, Response
|
2026-07-04 20:14:34 +02:00
|
|
|
from pydantic import BaseModel, Field
|
2026-07-04 20:09:54 +02:00
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
2026-07-04 20:14:34 +02:00
|
|
|
# str statt EmailStr: Self-Hosted/Dev nutzt oft .local-Domains (admin@kairo.local)
|
|
|
|
|
email: str = Field(min_length=3, max_length=255)
|
2026-07-04 20:09:54 +02:00
|
|
|
password: str = Field(min_length=8, max_length=256)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/login")
|
|
|
|
|
def auth_login(body: LoginRequest):
|
|
|
|
|
return login(body.email, body.password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/logout")
|
|
|
|
|
def auth_logout(response: Response, session: dict = Depends(require_auth)):
|
|
|
|
|
token = session.get("token")
|
|
|
|
|
if token:
|
|
|
|
|
logout(token)
|
|
|
|
|
return {"ok": True}
|