diff --git a/tests/auth-react/django3x/mysite/middleware.py b/tests/auth-react/django3x/mysite/middleware.py index c2555a6b..feeb1694 100644 --- a/tests/auth-react/django3x/mysite/middleware.py +++ b/tests/auth-react/django3x/mysite/middleware.py @@ -1,4 +1,5 @@ import asyncio +from typing import Callable from django.http import HttpRequest, HttpResponse @@ -23,3 +24,17 @@ def __middleware(request: HttpRequest): # type: ignore return response # type: ignore return __middleware + + +def response_logging_middleware(get_response: Callable): # type: ignore + def middleware(request: HttpRequest) -> HttpResponse: + response = get_response(request) # type: ignore + + # Log the response + print(f"Path: {request.path} | Method: {request.method} | Status: {response.status_code}") # type: ignore + if hasattr(response, "content"): # type: ignore + print(f"Response: {response.content.decode('utf-8')}") # type: ignore + + return response # type: ignore + + return middleware diff --git a/tests/auth-react/django3x/mysite/settings.py b/tests/auth-react/django3x/mysite/settings.py index 6ad791b2..0ed74339 100644 --- a/tests/auth-react/django3x/mysite/settings.py +++ b/tests/auth-react/django3x/mysite/settings.py @@ -73,6 +73,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "supertokens_python.framework.django.django_middleware.middleware", + "mysite.middleware.response_logging_middleware", ] ROOT_URLCONF = "mysite.urls" diff --git a/tests/auth-react/django3x/mysite/store.py b/tests/auth-react/django3x/mysite/store.py index 3f2ece28..d1359937 100644 --- a/tests/auth-react/django3x/mysite/store.py +++ b/tests/auth-react/django3x/mysite/store.py @@ -1,3 +1,4 @@ +import time from typing import Any, Dict, List, Optional, Union from typing_extensions import Literal @@ -10,6 +11,13 @@ def save_url_with_token(url_with_token: str): def get_url_with_token() -> str: + t = 0 + while not latest_url_with_token: + time.sleep(0.5) + t += 1 + if t > 10: + break + return latest_url_with_token diff --git a/tests/auth-react/fastapi-server/app.py b/tests/auth-react/fastapi-server/app.py index 0c8fdc39..a697b1b9 100644 --- a/tests/auth-react/fastapi-server/app.py +++ b/tests/auth-react/fastapi-server/app.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. import os +import time import typing from typing import Any, Awaitable, Callable, Dict, List, Optional, Union @@ -172,6 +173,17 @@ app.add_middleware(get_middleware()) os.environ.setdefault("SUPERTOKENS_ENV", "testing") + +@app.middleware("http") +async def log_response(request: Request, call_next): # type: ignore + response = await call_next(request) # type: ignore + if isinstance(response, Response): + body = response.body + if isinstance(body, bytes): + print(f"Response: {body.decode('utf-8')}") + return response # type: ignore + + code_store: Dict[str, List[Dict[str, Any]]] = {} accountlinking_config: Dict[str, Any] = {} enabled_providers: Optional[List[Any]] = None @@ -1397,6 +1409,14 @@ async def get_session_info(session_: SessionContainer = Depends(verify_session() @app.get("/token") async def get_token(): global latest_url_with_token + t = 0 + + while not latest_url_with_token: + time.sleep(0.5) + t += 1 + if t > 10: + break + return JSONResponse({"latestURLWithToken": latest_url_with_token}) diff --git a/tests/auth-react/flask-server/app.py b/tests/auth-react/flask-server/app.py index c71851ac..7c19d5b6 100644 --- a/tests/auth-react/flask-server/app.py +++ b/tests/auth-react/flask-server/app.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. import os +import time import traceback from typing import Any, Awaitable, Callable, Dict, List, Optional, Union @@ -1094,6 +1095,12 @@ def make_default_options_response(): ) +@app.after_request +def after_request(response): # type: ignore + print(f"Response: {response.get_data(as_text=True)}") # type: ignore + return response # type: ignore + + @app.route("/ping", methods=["GET"]) # type: ignore def ping(): return "success" @@ -1284,6 +1291,14 @@ def get_session_info(): @app.route("/token", methods=["GET"]) # type: ignore def get_token(): global latest_url_with_token + + t = 0 + while not latest_url_with_token: + time.sleep(0.5) + t += 1 + if t > 10: + break + return jsonify({"latestURLWithToken": latest_url_with_token})