Skip to content

Commit f6cf304

Browse files
committed
fixes a small issue
1 parent 21ba18e commit f6cf304

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

supertokens_python/post_init_callbacks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ def run_post_init_callbacks() -> None:
2929
for cb in PostSTInitCallbacks.post_init_callbacks:
3030
cb()
3131
PostSTInitCallbacks.post_init_callbacks = []
32+
33+
@staticmethod
34+
def reset():
35+
PostSTInitCallbacks.post_init_callbacks = []

tests/test-server/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from supertokens_python.framework import BaseRequest, BaseResponse
66
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
77
from supertokens_python.ingredients.smsdelivery.types import SMSDeliveryConfig
8+
from supertokens_python.post_init_callbacks import PostSTInitCallbacks
89
from supertokens_python.recipe import (
910
accountlinking,
1011
dashboard,
@@ -202,6 +203,7 @@ async def default_func( # pylint: disable=unused-argument
202203

203204

204205
def st_reset():
206+
PostSTInitCallbacks.reset()
205207
override_logging.reset_override_logs()
206208
reset_override_params()
207209
ProcessState.get_instance().reset()

tests/test-server/override_logging.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Any, Callable, Coroutine, Dict, List, Set, Union
23
import time
34

@@ -151,5 +152,15 @@ def transform_logged_data(data: Any, visited: Union[Set[Any], None] = None) -> A
151152
return data.to_json()
152153
if isinstance(data, IsVerifiedSCV):
153154
return "IsVerifiedSCV"
155+
if is_jsonable(data):
156+
return data
154157

155-
return data
158+
return "Some custom object"
159+
160+
161+
def is_jsonable(x: Any) -> bool:
162+
try:
163+
json.dumps(x)
164+
return True
165+
except (TypeError, OverflowError):
166+
return False

tests/test-server/test_functions_mapper.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Callable, List, Union
22
from typing import Dict, Any, Optional
33
from supertokens_python.asyncio import list_users_by_account_info
4+
from supertokens_python.auth_utils import LinkingToSessionUserFailedError
45
from supertokens_python.recipe.accountlinking import (
56
RecipeLevelUser,
67
ShouldAutomaticallyLink,
@@ -35,6 +36,7 @@
3536
from supertokens_python.recipe.session.claims import PrimitiveClaim
3637
from supertokens_python.recipe.thirdparty.interfaces import (
3738
SignInUpNotAllowed,
39+
SignInUpOkResult,
3840
SignInUpPostNoEmailGivenByProviderResponse,
3941
SignInUpPostOkResult,
4042
)
@@ -309,6 +311,54 @@ def func1(
309311

310312
return func1
311313

314+
if eval_str.startswith("thirdparty.init.override.functions"):
315+
if "setIsVerifiedInSignInUp" in eval_str:
316+
from supertokens_python.recipe.thirdparty.interfaces import (
317+
RecipeInterface as ThirdPartyRecipeInterface,
318+
)
319+
320+
def custom_override(
321+
original_implementation: ThirdPartyRecipeInterface,
322+
) -> ThirdPartyRecipeInterface:
323+
og_sign_in_up = original_implementation.sign_in_up
324+
325+
async def sign_in_up(
326+
third_party_id: str,
327+
third_party_user_id: str,
328+
email: str,
329+
is_verified: bool,
330+
oauth_tokens: Dict[str, Any],
331+
raw_user_info_from_provider: RawUserInfoFromProvider,
332+
session: Optional[SessionContainer],
333+
should_try_linking_with_session_user: Union[bool, None],
334+
tenant_id: str,
335+
user_context: Dict[str, Any],
336+
) -> Union[
337+
SignInUpOkResult,
338+
SignInUpNotAllowed,
339+
LinkingToSessionUserFailedError,
340+
]:
341+
user_context[
342+
"isVerified"
343+
] = is_verified # this information comes from the third party provider
344+
return await og_sign_in_up(
345+
third_party_id,
346+
third_party_user_id,
347+
email,
348+
is_verified,
349+
oauth_tokens,
350+
raw_user_info_from_provider,
351+
session,
352+
should_try_linking_with_session_user,
353+
tenant_id,
354+
user_context,
355+
)
356+
357+
original_implementation.sign_in_up = sign_in_up
358+
return original_implementation
359+
360+
return custom_override
361+
312362
elif eval_str.startswith("passwordless.init.smsDelivery.service.sendSms"):
313363

314364
def func2(

0 commit comments

Comments
 (0)