Skip to content

Commit

Permalink
fixes a small issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 13, 2024
1 parent 21ba18e commit f6cf304
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions supertokens_python/post_init_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ def run_post_init_callbacks() -> None:
for cb in PostSTInitCallbacks.post_init_callbacks:
cb()
PostSTInitCallbacks.post_init_callbacks = []

@staticmethod
def reset():
PostSTInitCallbacks.post_init_callbacks = []
2 changes: 2 additions & 0 deletions tests/test-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from supertokens_python.framework import BaseRequest, BaseResponse
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
from supertokens_python.ingredients.smsdelivery.types import SMSDeliveryConfig
from supertokens_python.post_init_callbacks import PostSTInitCallbacks
from supertokens_python.recipe import (
accountlinking,
dashboard,
Expand Down Expand Up @@ -202,6 +203,7 @@ async def default_func( # pylint: disable=unused-argument


def st_reset():
PostSTInitCallbacks.reset()
override_logging.reset_override_logs()
reset_override_params()
ProcessState.get_instance().reset()
Expand Down
13 changes: 12 additions & 1 deletion tests/test-server/override_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Callable, Coroutine, Dict, List, Set, Union
import time

Expand Down Expand Up @@ -151,5 +152,15 @@ def transform_logged_data(data: Any, visited: Union[Set[Any], None] = None) -> A
return data.to_json()
if isinstance(data, IsVerifiedSCV):
return "IsVerifiedSCV"
if is_jsonable(data):
return data

return data
return "Some custom object"


def is_jsonable(x: Any) -> bool:
try:
json.dumps(x)
return True
except (TypeError, OverflowError):
return False
50 changes: 50 additions & 0 deletions tests/test-server/test_functions_mapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, List, Union
from typing import Dict, Any, Optional
from supertokens_python.asyncio import list_users_by_account_info
from supertokens_python.auth_utils import LinkingToSessionUserFailedError
from supertokens_python.recipe.accountlinking import (
RecipeLevelUser,
ShouldAutomaticallyLink,
Expand Down Expand Up @@ -35,6 +36,7 @@
from supertokens_python.recipe.session.claims import PrimitiveClaim
from supertokens_python.recipe.thirdparty.interfaces import (
SignInUpNotAllowed,
SignInUpOkResult,
SignInUpPostNoEmailGivenByProviderResponse,
SignInUpPostOkResult,
)
Expand Down Expand Up @@ -309,6 +311,54 @@ def func1(

return func1

if eval_str.startswith("thirdparty.init.override.functions"):
if "setIsVerifiedInSignInUp" in eval_str:
from supertokens_python.recipe.thirdparty.interfaces import (
RecipeInterface as ThirdPartyRecipeInterface,
)

def custom_override(
original_implementation: ThirdPartyRecipeInterface,
) -> ThirdPartyRecipeInterface:
og_sign_in_up = original_implementation.sign_in_up

async def sign_in_up(
third_party_id: str,
third_party_user_id: str,
email: str,
is_verified: bool,
oauth_tokens: Dict[str, Any],
raw_user_info_from_provider: RawUserInfoFromProvider,
session: Optional[SessionContainer],
should_try_linking_with_session_user: Union[bool, None],
tenant_id: str,
user_context: Dict[str, Any],
) -> Union[
SignInUpOkResult,
SignInUpNotAllowed,
LinkingToSessionUserFailedError,
]:
user_context[
"isVerified"
] = is_verified # this information comes from the third party provider
return await og_sign_in_up(
third_party_id,
third_party_user_id,
email,
is_verified,
oauth_tokens,
raw_user_info_from_provider,
session,
should_try_linking_with_session_user,
tenant_id,
user_context,
)

original_implementation.sign_in_up = sign_in_up
return original_implementation

return custom_override

elif eval_str.startswith("passwordless.init.smsDelivery.service.sendSms"):

def func2(
Expand Down

0 comments on commit f6cf304

Please sign in to comment.