Skip to content

Commit

Permalink
Merge pull request #400 from supertokens/tenant-id-compulsory
Browse files Browse the repository at this point in the history
refactor: Make tenant id compulsory in all recipe functions
  • Loading branch information
rishabhpoddar authored Aug 11, 2023
2 parents f16623e + 91198a0 commit fc4286b
Show file tree
Hide file tree
Showing 97 changed files with 624 additions and 674 deletions.
14 changes: 10 additions & 4 deletions supertokens_python/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,35 @@


async def get_users_oldest_first(
tenant_id: str,
limit: Union[int, None] = None,
pagination_token: Union[str, None] = None,
include_recipe_ids: Union[None, List[str]] = None,
query: Union[None, Dict[str, str]] = None,
) -> UsersResponse:
return await Supertokens.get_instance().get_users(
"ASC", limit, pagination_token, include_recipe_ids, query
tenant_id, "ASC", limit, pagination_token, include_recipe_ids, query
)


async def get_users_newest_first(
tenant_id: str,
limit: Union[int, None] = None,
pagination_token: Union[str, None] = None,
include_recipe_ids: Union[None, List[str]] = None,
query: Union[None, Dict[str, str]] = None,
) -> UsersResponse:
return await Supertokens.get_instance().get_users(
"DESC", limit, pagination_token, include_recipe_ids, query
tenant_id, "DESC", limit, pagination_token, include_recipe_ids, query
)


async def get_user_count(include_recipe_ids: Union[None, List[str]] = None) -> int:
return await Supertokens.get_instance().get_user_count(include_recipe_ids)
async def get_user_count(
include_recipe_ids: Union[None, List[str]] = None, tenant_id: Optional[str] = None
) -> int:
return await Supertokens.get_instance().get_user_count(
include_recipe_ids, tenant_id
)


async def delete_user(user_id: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def handle_user_email_verify_put(

if verified:
token_response = await create_email_verification_token(
user_id, tenant_id=tenant_id, user_context=user_context
tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context
)

if isinstance(
Expand All @@ -49,7 +49,7 @@ async def handle_user_email_verify_put(
return UserEmailVerifyPutAPIResponse()

verify_response = await verify_email_using_token(
token_response.token, tenant_id, user_context=user_context
tenant_id=tenant_id, token=token_response.token, user_context=user_context
)

if isinstance(verify_response, VerifyEmailUsingTokenInvalidTokenError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ async def handle_email_verify_token_post(
"Required parameter 'userId' is missing or has an invalid type"
)

res = await send_email_verification_email(user_id, None, tenant_id, user_context)
res = await send_email_verification_email(
tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context
)

if isinstance(res, SendEmailVerificationEmailAlreadyVerifiedError):
return UserEmailVerifyTokenPostAPIEmailAlreadyVerifiedErrorResponse()
Expand Down
7 changes: 4 additions & 3 deletions supertokens_python/recipe/dashboard/api/users_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import asyncio
from typing import TYPE_CHECKING, Any, Awaitable, List, Dict
from typing_extensions import Literal

from supertokens_python.supertokens import Supertokens

Expand Down Expand Up @@ -45,7 +46,7 @@ async def handle_users_get_api(
if limit is None:
raise_bad_input_exception("Missing required parameter 'limit'")

time_joined_order: str = api_options.request.get_query_param( # type: ignore
time_joined_order: Literal["ASC", "DESC"] = api_options.request.get_query_param( # type: ignore
"timeJoinedOrder", "DESC"
)
if time_joined_order not in ["ASC", "DESC"]:
Expand All @@ -54,12 +55,12 @@ async def handle_users_get_api(
pagination_token = api_options.request.get_query_param("paginationToken")

users_response = await Supertokens.get_instance().get_users(
tenant_id,
time_joined_order=time_joined_order,
limit=int(limit),
time_joined_order=time_joined_order, # type: ignore
pagination_token=pagination_token,
include_recipe_ids=None,
query=api_options.request.get_query_params(),
tenant_id=tenant_id,
)

# user metadata bulk fetch with batches:
Expand Down
12 changes: 6 additions & 6 deletions supertokens_python/recipe/emailpassword/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ async def sign_in_post(

user = result.user
session = await create_new_session(
api_options.request,
user.user_id,
tenant_id=tenant_id,
request=api_options.request,
user_id=user.user_id,
access_token_payload={},
session_data_in_database={},
tenant_id=tenant_id,
user_context=user_context,
)
return SignInPostOkResult(user, session)
Expand Down Expand Up @@ -213,11 +213,11 @@ async def sign_up_post(

user = result.user
session = await create_new_session(
api_options.request,
user.user_id,
tenant_id=tenant_id,
request=api_options.request,
user_id=user.user_id,
access_token_payload={},
session_data_in_database={},
tenant_id=tenant_id,
user_context=user_context,
)
return SignUpPostOkResult(user, session)
38 changes: 15 additions & 23 deletions supertokens_python/recipe/emailpassword/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,65 +65,61 @@ async def get_user_by_id(


async def get_user_by_email(
email: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None
) -> Union[User, None]:
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_email(
email, tenant_id or DEFAULT_TENANT_ID, user_context
tenant_id, email, user_context
)


async def create_reset_password_token(
user_id: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
tenant_id: str, user_id: str, user_context: Union[None, Dict[str, Any]] = None
):
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().recipe_implementation.create_reset_password_token(
user_id, tenant_id or DEFAULT_TENANT_ID, user_context
user_id, tenant_id, user_context
)


async def reset_password_using_token(
tenant_id: str,
token: str,
new_password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token(
token, new_password, tenant_id or DEFAULT_TENANT_ID, user_context
new_password, tenant_id, token, user_context
)


async def sign_in(
tenant_id: str,
email: str,
password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_in(
email, password, tenant_id or DEFAULT_TENANT_ID, user_context
email, password, tenant_id, user_context
)


async def sign_up(
tenant_id: str,
email: str,
password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_up(
email, password, tenant_id or DEFAULT_TENANT_ID, user_context
email, password, tenant_id, user_context
)


Expand All @@ -139,11 +135,9 @@ async def send_email(


async def create_reset_password_link(
user_id: str,
tenant_id: Optional[str] = None,
user_context: Optional[Dict[str, Any]] = None,
tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None
):
token = await create_reset_password_token(user_id, tenant_id, user_context)
token = await create_reset_password_token(tenant_id, user_id, user_context)
if isinstance(token, CreateResetPasswordWrongUserIdError):
return CreateResetPasswordLinkUknownUserIdError()

Expand All @@ -153,17 +147,15 @@ async def create_reset_password_link(
recipe_instance.get_app_info(),
recipe_instance.get_recipe_id(),
token.token,
tenant_id or DEFAULT_TENANT_ID,
tenant_id,
)
)


async def send_reset_password_email(
user_id: str,
tenant_id: Optional[str] = None,
user_context: Optional[Dict[str, Any]] = None,
tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None
):
link = await create_reset_password_link(user_id, tenant_id, user_context)
link = await create_reset_password_link(tenant_id, user_id, user_context)
if isinstance(link, CreateResetPasswordLinkUknownUserIdError):
return SendResetPasswordEmailUnknownUserIdError()

Expand Down
28 changes: 14 additions & 14 deletions supertokens_python/recipe/emailpassword/syncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,62 +50,62 @@ def get_user_by_id(


def get_user_by_email(
tenant_id: str,
email: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[None, User]:
from supertokens_python.recipe.emailpassword.asyncio import get_user_by_email

return sync(get_user_by_email(email, tenant_id, user_context))
return sync(get_user_by_email(tenant_id, email, user_context))


def create_reset_password_token(
tenant_id: str,
user_id: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import (
create_reset_password_token,
)

return sync(create_reset_password_token(user_id, tenant_id, user_context))
return sync(create_reset_password_token(tenant_id, user_id, user_context))


def reset_password_using_token(
tenant_id: str,
token: str,
new_password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import (
reset_password_using_token,
)

return sync(
reset_password_using_token(token, new_password, tenant_id, user_context)
reset_password_using_token(tenant_id, token, new_password, user_context)
)


def sign_in(
tenant_id: str,
email: str,
password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[SignInOkResult, SignInWrongCredentialsError]:
from supertokens_python.recipe.emailpassword.asyncio import sign_in

return sync(sign_in(email, password, tenant_id, user_context))
return sync(sign_in(tenant_id, email, password, user_context))


def sign_up(
tenant_id: str,
email: str,
password: str,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import sign_up

return sync(sign_up(email, password, tenant_id, user_context))
return sync(sign_up(tenant_id, email, password, user_context))


def send_email(
Expand All @@ -118,24 +118,24 @@ def send_email(


def create_reset_password_link(
tenant_id: str,
user_id: str,
tenant_id: Optional[str] = None,
user_context: Optional[Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import (
create_reset_password_link,
)

return sync(create_reset_password_link(user_id, tenant_id, user_context))
return sync(create_reset_password_link(tenant_id, user_id, user_context))


def send_reset_password_email(
tenant_id: str,
user_id: str,
tenant_id: Optional[str] = None,
user_context: Optional[Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import (
send_reset_password_email,
)

return sync(send_reset_password_email(user_id, tenant_id, user_context))
return sync(send_reset_password_email(tenant_id, user_id, user_context))
4 changes: 2 additions & 2 deletions supertokens_python/recipe/emailpassword/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations
from typing import Awaitable, Callable, List, TypeVar, Union, Optional
from typing import Awaitable, Callable, List, TypeVar, Union

from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
from supertokens_python.ingredients.emaildelivery.types import (
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
self,
user: PasswordResetEmailTemplateVarsUser,
password_reset_link: str,
tenant_id: Optional[str],
tenant_id: str,
) -> None:
self.user = user
self.password_reset_link = password_reset_link
Expand Down
Loading

0 comments on commit fc4286b

Please sign in to comment.