Skip to content

Commit

Permalink
Merge branch 'fix/session-mt' into feat/dashboard-mt
Browse files Browse the repository at this point in the history
  • Loading branch information
KShivendu committed Aug 2, 2023
2 parents 9c49016 + c2c85b7 commit 5557322
Show file tree
Hide file tree
Showing 51 changed files with 140 additions and 175 deletions.
4 changes: 1 addition & 3 deletions supertokens_python/ingredients/emaildelivery/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

class EmailDeliveryInterface(ABC, Generic[_T]):
@abstractmethod
async def send_email(
self, template_vars: _T, tenant_id: str, user_context: Dict[str, Any]
) -> None:
async def send_email(self, template_vars: _T, user_context: Dict[str, Any]) -> None:
pass


Expand Down
4 changes: 1 addition & 3 deletions supertokens_python/ingredients/smsdelivery/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

class SMSDeliveryInterface(ABC, Generic[_T]):
@abstractmethod
async def send_sms(
self, template_vars: _T, tenant_id: str, user_context: Dict[str, Any]
) -> None:
async def send_sms(self, template_vars: _T, user_context: Dict[str, Any]) -> None:
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def handle_email_verify_token_post(
VerificationEmailTemplateVars(
user=VerificationEmailTemplateVarsUser(user_id, email_response.email),
email_verify_link=email_verify_link,
user_context={},
tenant_id=tenant_id,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ async def generate_password_reset_token_post(
send_email_input = PasswordResetEmailTemplateVars(
user=PasswordResetEmailTemplateVarsUser(user.user_id, user.email),
password_reset_link=password_reset_link,
tenant_id=tenant_id,
)
await api_options.email_delivery.ingredient_interface_impl.send_email(
send_email_input, tenant_id, user_context
send_email_input, user_context
)

return GeneratePasswordResetTokenPostOkResult()
Expand Down
3 changes: 1 addition & 2 deletions supertokens_python/recipe/emailpassword/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ async def sign_up(

async def send_email(
input_: EmailTemplateVars,
tenant_id: str,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
return await EmailPasswordRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email(
input_, tenant_id, user_context
input_, user_context
)
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def __init__(
async def send_email(
self,
template_vars: EmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
user = await self.recipe_interface_impl.get_user_by_id(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(
async def send_email(
self,
template_vars: EmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
content = await self.service_implementation.get_content(
Expand Down
3 changes: 1 addition & 2 deletions supertokens_python/recipe/emailpassword/syncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ def sign_up(

def send_email(
input_: EmailTemplateVars,
tenant_id: str,
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailpassword.asyncio import send_email

return sync(send_email(input_, tenant_id, user_context))
return sync(send_email(input_, user_context))
4 changes: 3 additions & 1 deletion 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
from typing import Awaitable, Callable, List, TypeVar, Union, Optional

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


# Export:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ async def unverify_email(

async def send_email(
input_: EmailTemplateVars,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
return await EmailVerificationRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email(
input_, tenant_id or DEFAULT_TENANT_ID, user_context
input_, user_context
)
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(
async def send_email(
self,
template_vars: VerificationEmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(
async def send_email(
self,
template_vars: VerificationEmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
content = await self.service_implementation.get_content(
Expand Down
4 changes: 2 additions & 2 deletions supertokens_python/recipe/emailverification/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ async def generate_email_verify_token_post(
email_verification_email_delivery_input = VerificationEmailTemplateVars(
user=VerificationEmailTemplateVarsUser(user_id, email_info.email),
email_verify_link=email_verify_link,
user_context=user_context,
tenant_id=tenant_id,
)
await api_options.email_delivery.ingredient_interface_impl.send_email(
email_verification_email_delivery_input, tenant_id, user_context
email_verification_email_delivery_input, user_context
)
return GenerateEmailVerifyTokenPostOkResult()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_email_verification_token(

def verify_email_using_token(
token: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailverification.asyncio import (
Expand Down Expand Up @@ -82,9 +82,8 @@ def unverify_email(

def send_email(
input_: EmailTemplateVars,
tenant_id: Optional[str],
user_context: Union[None, Dict[str, Any]] = None,
):
from supertokens_python.recipe.emailverification.asyncio import send_email

return sync(send_email(input_, tenant_id, user_context))
return sync(send_email(input_, user_context))
6 changes: 3 additions & 3 deletions supertokens_python/recipe/emailverification/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# under the License.
from __future__ import annotations

from typing import Union, Dict, Any
from typing import Union, Optional

from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
from supertokens_python.ingredients.emaildelivery.types import (
Expand All @@ -39,11 +39,11 @@ def __init__(
self,
user: VerificationEmailTemplateVarsUser,
email_verify_link: str,
user_context: Dict[str, Any],
tenant_id: Optional[str],
) -> None:
self.user = user
self.email_verify_link = email_verify_link
self.user_context = user_context
self.tenant_id = tenant_id


# Export:
Expand Down
12 changes: 8 additions & 4 deletions supertokens_python/recipe/passwordless/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ async def create_code_post(
url_with_link_code=magic_link,
code_life_time=response.code_life_time,
pre_auth_session_id=response.pre_auth_session_id,
tenant_id=tenant_id,
)
await api_options.email_delivery.ingredient_interface_impl.send_email(
passwordless_email_delivery_input, tenant_id, user_context
passwordless_email_delivery_input, user_context
)
elif isinstance(
api_options.config.contact_config,
Expand All @@ -115,9 +116,10 @@ async def create_code_post(
url_with_link_code=magic_link,
code_life_time=response.code_life_time,
pre_auth_session_id=response.pre_auth_session_id,
tenant_id=tenant_id,
)
await api_options.sms_delivery.ingredient_interface_impl.send_sms(
sms_input, tenant_id, user_context
sms_input, user_context
)

return CreateCodePostOkResult(
Expand Down Expand Up @@ -214,10 +216,11 @@ async def resend_code_post(
url_with_link_code=magic_link,
code_life_time=response.code_life_time,
pre_auth_session_id=response.pre_auth_session_id,
tenant_id=tenant_id,
)
)
await api_options.email_delivery.ingredient_interface_impl.send_email(
passwordless_email_delivery_input, tenant_id, user_context
passwordless_email_delivery_input, user_context
)
elif isinstance(
api_options.config.contact_config,
Expand All @@ -234,9 +237,10 @@ async def resend_code_post(
url_with_link_code=magic_link,
code_life_time=response.code_life_time,
pre_auth_session_id=response.pre_auth_session_id,
tenant_id=tenant_id,
)
await api_options.sms_delivery.ingredient_interface_impl.send_sms(
sms_input, tenant_id, user_context
sms_input, user_context
)
return ResendCodePostOkResult()
return ResendCodePostRestartFlowError()
Expand Down
18 changes: 11 additions & 7 deletions supertokens_python/recipe/passwordless/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def get_user_by_email(

async def get_user_by_phone_number(
phone_number: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[User, None]:
if user_context is None:
Expand Down Expand Up @@ -246,7 +246,7 @@ async def list_codes_by_phone_number(

async def list_codes_by_device_id(
device_id: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[DeviceType, None]:
if user_context is None:
Expand All @@ -260,7 +260,7 @@ async def list_codes_by_device_id(

async def list_codes_by_pre_auth_session_id(
pre_auth_session_id: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[DeviceType, None]:
if user_context is None:
Expand Down Expand Up @@ -306,23 +306,27 @@ async def signinup(

async def send_email(
input_: EmailTemplateVars,
tenant_id: Optional[str],
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
if input_.tenant_id is None:
input_.tenant_id = DEFAULT_TENANT_ID

return await PasswordlessRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email(
input_, tenant_id or DEFAULT_TENANT_ID, user_context
input_, user_context
)


async def send_sms(
input_: SMSTemplateVars,
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}
if input_.tenant_id is None:
input_.tenant_id = DEFAULT_TENANT_ID

return await PasswordlessRecipe.get_instance().sms_delivery.ingredient_interface_impl.send_sms(
input_, tenant_id or DEFAULT_TENANT_ID, user_context
input_, user_context
)
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def __init__(
async def send_email(
self,
template_vars: PasswordlessLoginEmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
await self.create_and_send_custom_email(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(
async def send_email(
self,
template_vars: PasswordlessLoginEmailTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
content = await self.service_implementation.get_content(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def __init__(
async def send_sms(
self,
template_vars: PasswordlessLoginSMSTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
await self.create_and_send_custom_sms(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, api_key: str) -> None:
async def send_sms(
self,
template_vars: PasswordlessLoginSMSTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
supertokens = Supertokens.get_instance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(
async def send_sms(
self,
template_vars: PasswordlessLoginSMSTemplateVars,
tenant_id: str,
user_context: Dict[str, Any],
) -> None:
content = await self.service_implementation.get_content(
Expand Down
16 changes: 7 additions & 9 deletions supertokens_python/recipe/passwordless/syncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_user_by_email(

def get_user_by_phone_number(
phone_number: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[User, None]:
return sync(
Expand Down Expand Up @@ -195,7 +195,7 @@ def list_codes_by_phone_number(

def list_codes_by_device_id(
device_id: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[DeviceType, None]:
return sync(
Expand All @@ -207,7 +207,7 @@ def list_codes_by_device_id(

def list_codes_by_pre_auth_session_id(
pre_auth_session_id: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[DeviceType, None]:
return sync(
Expand All @@ -222,7 +222,7 @@ def list_codes_by_pre_auth_session_id(
def create_magic_link(
email: Union[str, None],
phone_number: Union[str, None],
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> str:
return sync(
Expand All @@ -238,7 +238,7 @@ def create_magic_link(
def signinup(
email: Union[str, None],
phone_number: Union[str, None],
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> ConsumeCodeOkResult:
return sync(
Expand All @@ -253,15 +253,13 @@ def signinup(

def send_email(
input_: PasswordlessLoginEmailTemplateVars,
tenant_id: Optional[str],
user_context: Union[None, Dict[str, Any]] = None,
) -> None:
return sync(asyncio.send_email(input_, tenant_id, user_context))
return sync(asyncio.send_email(input_, user_context))


def send_sms(
input_: PasswordlessLoginSMSTemplateVars,
tenant_id: Optional[str],
user_context: Union[None, Dict[str, Any]] = None,
) -> None:
return sync(asyncio.send_sms(input_, tenant_id, user_context))
return sync(asyncio.send_sms(input_, user_context))
Loading

0 comments on commit 5557322

Please sign in to comment.