| | |
| | | "/miniapp", |
| | | "/miniapp/login", |
| | | ) or request.path.startswith("/static") |
| | | |
| | | # Для API запросов возвращаем JSON вместо редиректа |
| | | is_api = request.path.startswith("/api/") |
| | | |
| | | if request["user"] is None and not public: |
| | | if is_api: |
| | | return web.json_response({"ok": False, "msg": "Не авторизован."}, status=401) |
| | | raise web.HTTPFound("/login") |
| | | return await handler(request) |
| | | try: |
| | | response = await handler(request) |
| | | except web.HTTPException as response: |
| | | if request.path.startswith("/miniapp") or request.path == "/auth/miniapp": |
| | | response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" |
| | | response.headers["Pragma"] = "no-cache" |
| | | raise |
| | | if request.path.startswith("/miniapp") or request.path == "/auth/miniapp": |
| | | response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" |
| | | response.headers["Pragma"] = "no-cache" |
| | | if request.path.startswith("/static/"): |
| | | response.headers["Cache-Control"] = "no-cache, must-revalidate, max-age=0" |
| | | return response |
| | | |
| | | |
| | | async def login_page(request) -> web.Response: |
| | |
| | | token, |
| | | max_age=SESS_TTL, |
| | | httponly=True, |
| | | samesite="Lax", |
| | | secure=base_url(request).startswith("https"), |
| | | samesite="None", |
| | | secure=True, |
| | | ) |
| | | return resp |
| | | |