Skip to content

Commit c844d0e

Browse files
committed
fix: Handle edge cases for verify_session decorator
1 parent 105947b commit c844d0e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [unreleased]
1010

11+
### Changes
12+
13+
- Throw error when `verify_sesion` is used with a view that allows `OPTIONS` or `TRACE` requests
14+
- Allow `verify_session` decorator to be with `@app.before_request` in Flask without returning a response
15+
1116

1217
## [0.14.3] - 2023-06-7
1318

supertokens_python/recipe/session/api/implementation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ async def verify_session(
7373
) -> Union[SessionContainer, None]:
7474
method = normalise_http_method(api_options.request.method())
7575
if method in ("options", "trace"):
76+
if session_required:
77+
raise Exception(f"verify_session cannot be used with {method} method")
7678
return None
7779
incoming_path = NormalisedURLPath(api_options.request.get_path())
7880
refresh_token_path = api_options.config.refresh_token_path

supertokens_python/recipe/session/framework/flask/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def wrapped_function(*args: Any, **kwargs: Any):
6161
baseRequest.set_session_as_none()
6262
else:
6363
baseRequest.set_session(session)
64-
response = make_response(f(*args, **kwargs))
65-
return response
64+
65+
response = f(*args, **kwargs)
66+
return make_response(response) if response is not None else None
6667

6768
return cast(_T, wrapped_function)
6869

0 commit comments

Comments
 (0)