Files
quart-imp/docs/_md/v1/quart_imp_security-api_login_check.md

48 lines
1.0 KiB
Markdown
Raw Normal View History

2024-08-16 15:09:07 +01:00
```
Menu = quart_imp.security/api_login_check
Title = api_login_check - quart_imp.security
```
```python
from quart_imp.security import api_login_check
```
```python
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.
##### Example:
```python
@bp.route("/api/resource", methods=["GET"])
@api_login_check('logged_in', True)
async def api_page():
...
```
##### Example of defined fail_json:
```python
@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():
...
```