from quart_imp.security import api_login_check
api_login_check(
session_key: str,
values_allowed: t.Union[t.List[t.Union[str, int, bool]], str, int, bool],
fail_json: t.Optional[t.Dict[str, t.Any]] = None
)
@api_login_check(...)
A decorator that is used to secure API routes that return JSON responses.
session_key
The session key to check for.
values_allowed
A list of or singular value(s) that the session key must contain.
fail_json
JSON that is returned on failure. {"error": "You are not logged in."}
by default.
@bp.route("/api/resource", methods=["GET"])
@api_login_check('logged_in', True)
async def api_page():
...
@bp.route("/api/resource", methods=["GET"])
@api_login_check('logged_in', True, fail_json={"failed": "You need to be logged in."})
async def api_page():
...