Skip to content

Commit 8b72626

Browse files
committed
refactor: moves is_recipe_initialized to SuperTokens class
1 parent e7a10d1 commit 8b72626

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

supertokens_python/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
SupertokensInputConfig,
3131
SupertokensPublicConfig,
3232
get_request_from_user_context,
33+
is_recipe_initialized,
3334
)
3435

3536
# Some Pydantic models need a rebuild to resolve ForwardRefs
@@ -86,4 +87,5 @@ def convert_to_recipe_user_id(user_id: str) -> RecipeUserId:
8687
"get_all_cors_headers",
8788
"get_request_from_user_context",
8889
"init",
90+
"is_recipe_initialized",
8991
]

supertokens_python/asyncio/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,6 @@ async def list_users_by_account_info(
176176
)
177177

178178

179-
# Async not really required, but keeping for consistency
180-
async def is_recipe_initialized(recipe_id: str) -> bool:
181-
"""
182-
Check if a recipe is initialized.
183-
:param recipe_id: The ID of the recipe to check.
184-
:return: Whether the recipe is initialized.
185-
"""
186-
return any(
187-
recipe.get_recipe_id() == recipe_id
188-
for recipe in Supertokens.get_instance().recipe_modules
189-
)
190-
191-
192179
async def get_available_first_factors(
193180
tenant_id: str,
194181
session: Optional[SessionContainer],

supertokens_python/supertokens.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,22 @@ def get_request_from_user_context(
943943

944944
return user_context.get("_default", {}).get("request")
945945

946+
def is_recipe_initialized(self, recipe_id: str) -> bool:
947+
"""
948+
Check if a recipe is initialized.
949+
:param recipe_id: The ID of the recipe to check.
950+
:return: Whether the recipe is initialized.
951+
"""
952+
return any(
953+
recipe.get_recipe_id() == recipe_id for recipe in self.recipe_modules
954+
)
955+
946956

947957
def get_request_from_user_context(
948958
user_context: Optional[UserContext],
949959
) -> Optional[BaseRequest]:
950960
return Supertokens.get_instance().get_request_from_user_context(user_context)
961+
962+
963+
def is_recipe_initialized(recipe_id: str) -> bool:
964+
return Supertokens.get_instance().is_recipe_initialized(recipe_id)

supertokens_python/syncio/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,6 @@ def list_users_by_account_info(
181181
)
182182

183183

184-
def is_recipe_initialized(recipe_id: str) -> bool:
185-
"""
186-
Check if a recipe is initialized.
187-
:param recipe_id: The ID of the recipe to check.
188-
:return: Whether the recipe is initialized.
189-
"""
190-
from supertokens_python.asyncio import (
191-
is_recipe_initialized as async_is_recipe_initialized,
192-
)
193-
194-
return sync(async_is_recipe_initialized(recipe_id))
195-
196-
197184
def get_available_first_factors(
198185
tenant_id: str,
199186
session: Optional[SessionContainer],

0 commit comments

Comments
 (0)