Skip to content

Commit fc4286b

Browse files
Merge pull request #400 from supertokens/tenant-id-compulsory
refactor: Make tenant id compulsory in all recipe functions
2 parents f16623e + 91198a0 commit fc4286b

File tree

97 files changed

+624
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+624
-674
lines changed

supertokens_python/asyncio/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,35 @@
2828

2929

3030
async def get_users_oldest_first(
31+
tenant_id: str,
3132
limit: Union[int, None] = None,
3233
pagination_token: Union[str, None] = None,
3334
include_recipe_ids: Union[None, List[str]] = None,
3435
query: Union[None, Dict[str, str]] = None,
3536
) -> UsersResponse:
3637
return await Supertokens.get_instance().get_users(
37-
"ASC", limit, pagination_token, include_recipe_ids, query
38+
tenant_id, "ASC", limit, pagination_token, include_recipe_ids, query
3839
)
3940

4041

4142
async def get_users_newest_first(
43+
tenant_id: str,
4244
limit: Union[int, None] = None,
4345
pagination_token: Union[str, None] = None,
4446
include_recipe_ids: Union[None, List[str]] = None,
4547
query: Union[None, Dict[str, str]] = None,
4648
) -> UsersResponse:
4749
return await Supertokens.get_instance().get_users(
48-
"DESC", limit, pagination_token, include_recipe_ids, query
50+
tenant_id, "DESC", limit, pagination_token, include_recipe_ids, query
4951
)
5052

5153

52-
async def get_user_count(include_recipe_ids: Union[None, List[str]] = None) -> int:
53-
return await Supertokens.get_instance().get_user_count(include_recipe_ids)
54+
async def get_user_count(
55+
include_recipe_ids: Union[None, List[str]] = None, tenant_id: Optional[str] = None
56+
) -> int:
57+
return await Supertokens.get_instance().get_user_count(
58+
include_recipe_ids, tenant_id
59+
)
5460

5561

5662
async def delete_user(user_id: str) -> None:

supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_put.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def handle_user_email_verify_put(
4040

4141
if verified:
4242
token_response = await create_email_verification_token(
43-
user_id, tenant_id=tenant_id, user_context=user_context
43+
tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context
4444
)
4545

4646
if isinstance(
@@ -49,7 +49,7 @@ async def handle_user_email_verify_put(
4949
return UserEmailVerifyPutAPIResponse()
5050

5151
verify_response = await verify_email_using_token(
52-
token_response.token, tenant_id, user_context=user_context
52+
tenant_id=tenant_id, token=token_response.token, user_context=user_context
5353
)
5454

5555
if isinstance(verify_response, VerifyEmailUsingTokenInvalidTokenError):

supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_token_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ async def handle_email_verify_token_post(
3131
"Required parameter 'userId' is missing or has an invalid type"
3232
)
3333

34-
res = await send_email_verification_email(user_id, None, tenant_id, user_context)
34+
res = await send_email_verification_email(
35+
tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context
36+
)
3537

3638
if isinstance(res, SendEmailVerificationEmailAlreadyVerifiedError):
3739
return UserEmailVerifyTokenPostAPIEmailAlreadyVerifiedErrorResponse()

supertokens_python/recipe/dashboard/api/users_get.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import asyncio
1717
from typing import TYPE_CHECKING, Any, Awaitable, List, Dict
18+
from typing_extensions import Literal
1819

1920
from supertokens_python.supertokens import Supertokens
2021

@@ -45,7 +46,7 @@ async def handle_users_get_api(
4546
if limit is None:
4647
raise_bad_input_exception("Missing required parameter 'limit'")
4748

48-
time_joined_order: str = api_options.request.get_query_param( # type: ignore
49+
time_joined_order: Literal["ASC", "DESC"] = api_options.request.get_query_param( # type: ignore
4950
"timeJoinedOrder", "DESC"
5051
)
5152
if time_joined_order not in ["ASC", "DESC"]:
@@ -54,12 +55,12 @@ async def handle_users_get_api(
5455
pagination_token = api_options.request.get_query_param("paginationToken")
5556

5657
users_response = await Supertokens.get_instance().get_users(
58+
tenant_id,
59+
time_joined_order=time_joined_order,
5760
limit=int(limit),
58-
time_joined_order=time_joined_order, # type: ignore
5961
pagination_token=pagination_token,
6062
include_recipe_ids=None,
6163
query=api_options.request.get_query_params(),
62-
tenant_id=tenant_id,
6364
)
6465

6566
# user metadata bulk fetch with batches:

supertokens_python/recipe/emailpassword/api/implementation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ async def sign_in_post(
172172

173173
user = result.user
174174
session = await create_new_session(
175-
api_options.request,
176-
user.user_id,
175+
tenant_id=tenant_id,
176+
request=api_options.request,
177+
user_id=user.user_id,
177178
access_token_payload={},
178179
session_data_in_database={},
179-
tenant_id=tenant_id,
180180
user_context=user_context,
181181
)
182182
return SignInPostOkResult(user, session)
@@ -213,11 +213,11 @@ async def sign_up_post(
213213

214214
user = result.user
215215
session = await create_new_session(
216-
api_options.request,
217-
user.user_id,
216+
tenant_id=tenant_id,
217+
request=api_options.request,
218+
user_id=user.user_id,
218219
access_token_payload={},
219220
session_data_in_database={},
220-
tenant_id=tenant_id,
221221
user_context=user_context,
222222
)
223223
return SignUpPostOkResult(user, session)

supertokens_python/recipe/emailpassword/asyncio/__init__.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,65 +65,61 @@ async def get_user_by_id(
6565

6666

6767
async def get_user_by_email(
68-
email: str,
69-
tenant_id: Optional[str] = None,
70-
user_context: Union[None, Dict[str, Any]] = None,
68+
tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None
7169
) -> Union[User, None]:
7270
if user_context is None:
7371
user_context = {}
7472
return await EmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_email(
75-
email, tenant_id or DEFAULT_TENANT_ID, user_context
73+
tenant_id, email, user_context
7674
)
7775

7876

7977
async def create_reset_password_token(
80-
user_id: str,
81-
tenant_id: Optional[str] = None,
82-
user_context: Union[None, Dict[str, Any]] = None,
78+
tenant_id: str, user_id: str, user_context: Union[None, Dict[str, Any]] = None
8379
):
8480
if user_context is None:
8581
user_context = {}
8682
return await EmailPasswordRecipe.get_instance().recipe_implementation.create_reset_password_token(
87-
user_id, tenant_id or DEFAULT_TENANT_ID, user_context
83+
user_id, tenant_id, user_context
8884
)
8985

9086

9187
async def reset_password_using_token(
88+
tenant_id: str,
9289
token: str,
9390
new_password: str,
94-
tenant_id: Optional[str] = None,
9591
user_context: Union[None, Dict[str, Any]] = None,
9692
):
9793
if user_context is None:
9894
user_context = {}
9995
return await EmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token(
100-
token, new_password, tenant_id or DEFAULT_TENANT_ID, user_context
96+
new_password, tenant_id, token, user_context
10197
)
10298

10399

104100
async def sign_in(
101+
tenant_id: str,
105102
email: str,
106103
password: str,
107-
tenant_id: Optional[str] = None,
108104
user_context: Union[None, Dict[str, Any]] = None,
109105
):
110106
if user_context is None:
111107
user_context = {}
112108
return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_in(
113-
email, password, tenant_id or DEFAULT_TENANT_ID, user_context
109+
email, password, tenant_id, user_context
114110
)
115111

116112

117113
async def sign_up(
114+
tenant_id: str,
118115
email: str,
119116
password: str,
120-
tenant_id: Optional[str] = None,
121117
user_context: Union[None, Dict[str, Any]] = None,
122118
):
123119
if user_context is None:
124120
user_context = {}
125121
return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_up(
126-
email, password, tenant_id or DEFAULT_TENANT_ID, user_context
122+
email, password, tenant_id, user_context
127123
)
128124

129125

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

140136

141137
async def create_reset_password_link(
142-
user_id: str,
143-
tenant_id: Optional[str] = None,
144-
user_context: Optional[Dict[str, Any]] = None,
138+
tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None
145139
):
146-
token = await create_reset_password_token(user_id, tenant_id, user_context)
140+
token = await create_reset_password_token(tenant_id, user_id, user_context)
147141
if isinstance(token, CreateResetPasswordWrongUserIdError):
148142
return CreateResetPasswordLinkUknownUserIdError()
149143

@@ -153,17 +147,15 @@ async def create_reset_password_link(
153147
recipe_instance.get_app_info(),
154148
recipe_instance.get_recipe_id(),
155149
token.token,
156-
tenant_id or DEFAULT_TENANT_ID,
150+
tenant_id,
157151
)
158152
)
159153

160154

161155
async def send_reset_password_email(
162-
user_id: str,
163-
tenant_id: Optional[str] = None,
164-
user_context: Optional[Dict[str, Any]] = None,
156+
tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None
165157
):
166-
link = await create_reset_password_link(user_id, tenant_id, user_context)
158+
link = await create_reset_password_link(tenant_id, user_id, user_context)
167159
if isinstance(link, CreateResetPasswordLinkUknownUserIdError):
168160
return SendResetPasswordEmailUnknownUserIdError()
169161

supertokens_python/recipe/emailpassword/syncio/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,62 +50,62 @@ def get_user_by_id(
5050

5151

5252
def get_user_by_email(
53+
tenant_id: str,
5354
email: str,
54-
tenant_id: Optional[str] = None,
5555
user_context: Union[None, Dict[str, Any]] = None,
5656
) -> Union[None, User]:
5757
from supertokens_python.recipe.emailpassword.asyncio import get_user_by_email
5858

59-
return sync(get_user_by_email(email, tenant_id, user_context))
59+
return sync(get_user_by_email(tenant_id, email, user_context))
6060

6161

6262
def create_reset_password_token(
63+
tenant_id: str,
6364
user_id: str,
64-
tenant_id: Optional[str] = None,
6565
user_context: Union[None, Dict[str, Any]] = None,
6666
):
6767
from supertokens_python.recipe.emailpassword.asyncio import (
6868
create_reset_password_token,
6969
)
7070

71-
return sync(create_reset_password_token(user_id, tenant_id, user_context))
71+
return sync(create_reset_password_token(tenant_id, user_id, user_context))
7272

7373

7474
def reset_password_using_token(
75+
tenant_id: str,
7576
token: str,
7677
new_password: str,
77-
tenant_id: Optional[str] = None,
7878
user_context: Union[None, Dict[str, Any]] = None,
7979
):
8080
from supertokens_python.recipe.emailpassword.asyncio import (
8181
reset_password_using_token,
8282
)
8383

8484
return sync(
85-
reset_password_using_token(token, new_password, tenant_id, user_context)
85+
reset_password_using_token(tenant_id, token, new_password, user_context)
8686
)
8787

8888

8989
def sign_in(
90+
tenant_id: str,
9091
email: str,
9192
password: str,
92-
tenant_id: Optional[str] = None,
9393
user_context: Union[None, Dict[str, Any]] = None,
9494
) -> Union[SignInOkResult, SignInWrongCredentialsError]:
9595
from supertokens_python.recipe.emailpassword.asyncio import sign_in
9696

97-
return sync(sign_in(email, password, tenant_id, user_context))
97+
return sync(sign_in(tenant_id, email, password, user_context))
9898

9999

100100
def sign_up(
101+
tenant_id: str,
101102
email: str,
102103
password: str,
103-
tenant_id: Optional[str] = None,
104104
user_context: Union[None, Dict[str, Any]] = None,
105105
):
106106
from supertokens_python.recipe.emailpassword.asyncio import sign_up
107107

108-
return sync(sign_up(email, password, tenant_id, user_context))
108+
return sync(sign_up(tenant_id, email, password, user_context))
109109

110110

111111
def send_email(
@@ -118,24 +118,24 @@ def send_email(
118118

119119

120120
def create_reset_password_link(
121+
tenant_id: str,
121122
user_id: str,
122-
tenant_id: Optional[str] = None,
123123
user_context: Optional[Dict[str, Any]] = None,
124124
):
125125
from supertokens_python.recipe.emailpassword.asyncio import (
126126
create_reset_password_link,
127127
)
128128

129-
return sync(create_reset_password_link(user_id, tenant_id, user_context))
129+
return sync(create_reset_password_link(tenant_id, user_id, user_context))
130130

131131

132132
def send_reset_password_email(
133+
tenant_id: str,
133134
user_id: str,
134-
tenant_id: Optional[str] = None,
135135
user_context: Optional[Dict[str, Any]] = None,
136136
):
137137
from supertokens_python.recipe.emailpassword.asyncio import (
138138
send_reset_password_email,
139139
)
140140

141-
return sync(send_reset_password_email(user_id, tenant_id, user_context))
141+
return sync(send_reset_password_email(tenant_id, user_id, user_context))

supertokens_python/recipe/emailpassword/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from __future__ import annotations
15-
from typing import Awaitable, Callable, List, TypeVar, Union, Optional
15+
from typing import Awaitable, Callable, List, TypeVar, Union
1616

1717
from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
1818
from supertokens_python.ingredients.emaildelivery.types import (
@@ -99,7 +99,7 @@ def __init__(
9999
self,
100100
user: PasswordResetEmailTemplateVarsUser,
101101
password_reset_link: str,
102-
tenant_id: Optional[str],
102+
tenant_id: str,
103103
) -> None:
104104
self.user = user
105105
self.password_reset_link = password_reset_link

0 commit comments

Comments
 (0)