Skip to content

Commit 9e78f99

Browse files
committed
small changes
1 parent 0c48c1b commit 9e78f99

File tree

3 files changed

+11
-38
lines changed

3 files changed

+11
-38
lines changed

supertokens_python/recipe/multifactorauth/api/implementation.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
from __future__ import annotations
1515
import importlib
1616

17-
from typing import Any, Dict, List, Union, TYPE_CHECKING
17+
from typing import Any, Dict, List, Union
18+
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
19+
MultiFactorAuthClaim,
20+
)
1821

1922
from supertokens_python.recipe.session import SessionContainer
2023
from supertokens_python.recipe.multitenancy.asyncio import get_tenant
@@ -33,11 +36,6 @@
3336
ResyncSessionAndFetchMFAInfoPUTOkResult,
3437
)
3538

36-
if TYPE_CHECKING:
37-
from ..multi_factor_auth_claim import (
38-
MultiFactorAuthClaimClass as MultiFactorAuthClaimType,
39-
)
40-
4139

4240
class APIImplementation(APIInterface):
4341
async def resync_session_and_fetch_mfa_info_put(
@@ -47,10 +45,6 @@ async def resync_session_and_fetch_mfa_info_put(
4745
user_context: Dict[str, Any],
4846
) -> Union[ResyncSessionAndFetchMFAInfoPUTOkResult, GeneralErrorResponse]:
4947

50-
mfa = importlib.import_module("supertokens_python.recipe.multifactorauth")
51-
52-
MultiFactorAuthClaim: MultiFactorAuthClaimType = mfa.MultiFactorAuthClaim
53-
5448
module = importlib.import_module(
5549
"supertokens_python.recipe.multifactorauth.utils"
5650
)

supertokens_python/recipe/multifactorauth/utils.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from __future__ import annotations
15-
import importlib
16-
1715
from typing import TYPE_CHECKING, List, Optional, Union, Dict, Any
16+
from supertokens_python.recipe.multitenancy.asyncio import get_tenant
17+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
1818
from supertokens_python.recipe.session import SessionContainer
1919
from supertokens_python.recipe.session.asyncio import get_session_information
2020
from supertokens_python.recipe.session.exceptions import UnauthorisedError
@@ -35,9 +35,6 @@
3535
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
3636
MultiFactorAuthClaimClass,
3737
)
38-
from supertokens_python.recipe.multitenancy.recipe import (
39-
MultitenancyRecipe as MTRecipeType,
40-
)
4138

4239

4340
def validate_and_normalise_user_input(
@@ -203,16 +200,7 @@ async def user_getter():
203200
async def get_required_secondary_factors_for_tenant(
204201
tenant_id: str, user_context: Dict[str, Any]
205202
) -> List[str]:
206-
207-
MultitenancyRecipe = importlib.import_module(
208-
"supertokens_python.recipe.multitenancy.recipe"
209-
)
210-
211-
mt_recipe: MTRecipeType = MultitenancyRecipe.get_instance()
212-
213-
tenant_info = await mt_recipe.recipe_implementation.get_tenant(
214-
tenant_id=tenant_id, user_context=user_context
215-
)
203+
tenant_info = await get_tenant(tenant_id, user_context)
216204
if tenant_info is None:
217205
raise UnauthorisedError("Tenant not found")
218206
return (
@@ -276,14 +264,8 @@ async def is_valid_first_factor(
276264
tenant_id: str, factor_id: str, user_context: Dict[str, Any]
277265
) -> Literal["OK", "INVALID_FIRST_FACTOR_ERROR", "TENANT_NOT_FOUND_ERROR"]:
278266

279-
MultitenancyRecipe = importlib.import_module(
280-
"supertokens_python.recipe.multitenancy.recipe"
281-
)
282-
283-
mt_recipe: MTRecipeType = MultitenancyRecipe.get_instance()
284-
tenant_info = await mt_recipe.recipe_implementation.get_tenant(
285-
tenant_id=tenant_id, user_context=user_context
286-
)
267+
mt_recipe = MultitenancyRecipe.get_instance()
268+
tenant_info = await get_tenant(tenant_id=tenant_id, user_context=user_context)
287269
if tenant_info is None:
288270
return "TENANT_NOT_FOUND_ERROR"
289271

supertokens_python/supertokens.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# under the License.
1414

1515
from __future__ import annotations
16-
import importlib
1716

1817
from os import environ
1918
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Union, Tuple
@@ -277,11 +276,9 @@ def make_recipe(recipe: Callable[[AppInfo], RecipeModule]) -> RecipeModule:
277276
self.recipe_modules: List[RecipeModule] = list(map(make_recipe, recipe_list))
278277

279278
if not multitenancy_found:
280-
module = importlib.import_module(
281-
"supertokens_python.recipe.multitenancy.recipe"
282-
)
279+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
283280

284-
self.recipe_modules.append(module.init()(self.app_info))
281+
self.recipe_modules.append(MultitenancyRecipe.init()(self.app_info))
285282
if totp_found and not multi_factor_auth_found:
286283
raise Exception("Please initialize the MultiFactorAuth recipe to use TOTP.")
287284
if not user_metadata_found:

0 commit comments

Comments
 (0)