Skip to content

Commit 7614fc1

Browse files
committed
more fixes
1 parent 233f2bc commit 7614fc1

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

supertokens_python/recipe/session/recipe.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
TokenTransferMethod,
6161
validate_and_normalise_user_input,
6262
)
63+
from .cookie_and_header import clear_session_from_all_token_transfer_methods
6364

6465

6566
class SessionRecipe(RecipeModule):
@@ -235,13 +236,22 @@ async def handle_error(
235236

236237
if isinstance(err, UnauthorisedError):
237238
log_debug_message("errorHandler: returning UNAUTHORISED")
239+
if err.clear_tokens:
240+
log_debug_message("Clearing tokens because of UNAUTHORISED response")
241+
clear_session_from_all_token_transfer_methods(
242+
response, self, request, user_context
243+
)
238244
return await self.config.error_handlers.on_unauthorised(
239-
self, err.clear_tokens, request, str(err), response, user_context
245+
request, str(err), response
240246
)
241247
if isinstance(err, TokenTheftError):
242248
log_debug_message("errorHandler: returning TOKEN_THEFT_DETECTED")
249+
log_debug_message("Clearing tokens because of TOKEN_THEFT_DETECTED response")
250+
clear_session_from_all_token_transfer_methods(
251+
response, self, request, user_context
252+
)
243253
return await self.config.error_handlers.on_token_theft_detected(
244-
self, request, err.session_handle, err.user_id, response, user_context
254+
request, err.session_handle, err.user_id, response
245255
)
246256
if isinstance(err, InvalidClaimsError):
247257
log_debug_message("errorHandler: returning INVALID_CLAIMS")

supertokens_python/recipe/session/utils.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,11 @@ def __init__(
126126

127127
async def on_token_theft_detected(
128128
self,
129-
recipe: SessionRecipe,
130129
request: BaseRequest,
131130
session_handle: str,
132131
user_id: str,
133132
response: BaseResponse,
134-
user_context: Dict[str, Any],
135133
) -> BaseResponse:
136-
log_debug_message("Clearing tokens because of TOKEN_THEFT_DETECTED response")
137-
clear_session_from_all_token_transfer_methods(
138-
response, recipe, request, user_context
139-
)
140134
return await resolve(
141135
self.__on_token_theft_detected(request, session_handle, user_id, response)
142136
)
@@ -149,18 +143,10 @@ async def on_try_refresh_token(
149143

150144
async def on_unauthorised(
151145
self,
152-
recipe: SessionRecipe,
153-
do_clear_cookies: bool,
154146
request: BaseRequest,
155147
message: str,
156148
response: BaseResponse,
157-
user_context: Dict[str, Any],
158149
):
159-
if do_clear_cookies:
160-
log_debug_message("Clearing tokens because of UNAUTHORISED response")
161-
clear_session_from_all_token_transfer_methods(
162-
response, recipe, request, user_context
163-
)
164150
return await resolve(self.__on_unauthorised(request, message, response))
165151

166152
async def on_invalid_claim(

0 commit comments

Comments
 (0)