"""Auth routes: login + current user. No self-registration.""" from __future__ import annotations from flask import Blueprint, jsonify, request from ..auth.users import AuthError from .helpers import ApiError, current_user, require_auth auth_bp = Blueprint("auth", __name__) def _store(): from flask import current_app return current_app.extensions["user_store"] @auth_bp.post("/login") def login(): data = request.get_json(silent=True) or {} email = (data.get("email") or "").strip().lower() password = data.get("password") or "" if not email or not password: raise ApiError("email and password are required") try: user = _store().verify(email, password) token = _store().issue_token(user) except AuthError as exc: raise ApiError(str(exc), 401) return jsonify({"token": token, "user": _store().public_user(user)}) @auth_bp.get("/me") @require_auth def me(): return jsonify({"user": _store().public_user(current_user())})