Skip to content

Commit

Permalink
fixes stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 12, 2024
1 parent 9e0406a commit 3634233
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
3 changes: 1 addition & 2 deletions supertokens_python/recipe/accountlinking/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ def __init__(


class LinkAccountsInputUserNotPrimaryError:
def __init__(self, description: Optional[str] = None):
def __init__(self):
self.status: Literal[
"INPUT_USER_IS_NOT_A_PRIMARY_USER"
] = "INPUT_USER_IS_NOT_A_PRIMARY_USER"
self.description = description


class UnlinkAccountOkResult:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ async def link_accounts(
description=response["description"],
)
elif response["status"] == "INPUT_USER_IS_NOT_A_PRIMARY_USER":
return LinkAccountsInputUserNotPrimaryError(
description=response["description"],
)
return LinkAccountsInputUserNotPrimaryError()
else:
raise Exception(f"Unknown response status: {response['status']}")

Expand Down
1 change: 0 additions & 1 deletion tests/test-server/accountlinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def link_accounts_api(): # type: ignore
else:
return jsonify(
{
"description": response.description,
"status": response.status,
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ async def custom_unauthorised_callback(
),
on_account_linked=callback_with_log(
"AccountLinking.onAccountLinked",
recipe_config_json.get("on_account_linked"),
recipe_config_json.get("onAccountLinked"),
),
override=accountlinking.InputOverrideConfig(
functions=override_builder_with_logging(
Expand Down
3 changes: 3 additions & 0 deletions tests/test-server/override_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from httpx import Response

from supertokens_python.framework.flask.flask_request import FlaskRequest
from supertokens_python.recipe.accountlinking import RecipeLevelUser
from supertokens_python.recipe.accountlinking.interfaces import (
CreatePrimaryUserOkResult,
LinkAccountsOkResult,
Expand Down Expand Up @@ -134,4 +135,6 @@ def transform_logged_data(data: Any, visited: Union[Set[Any], None] = None) -> A
return {"status": "EMAIL_ALREADY_VERIFIED_ERROR"}
if isinstance(data, PasswordResetPostOkResult):
return {"status": "OK", "user": data.user.to_json(), "email": data.email}
if isinstance(data, RecipeLevelUser):
return data.to_json()
return data
7 changes: 4 additions & 3 deletions tests/test-server/passwordless.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def create_code_api(): # type: ignore
)
return jsonify(
{
"status": "OK",
"codeId": response.code_id,
"preAuthSessionId": response.pre_auth_session_id,
"codeLifeTime": response.code_life_time,
Expand All @@ -89,10 +90,10 @@ def consume_code_api(): # type: ignore
session = convert_session_to_container(body)

response = consume_code(
device_id=body["deviceId"],
pre_auth_session_id=body["preAuthSessionId"],
device_id=body.get("deviceId"),
pre_auth_session_id=body.get("preAuthSessionId"),
user_input_code=body.get("userInputCode"),
link_code=body["linkCode"],
link_code=body.get("linkCode", None),
tenant_id=body.get("tenantId", "public"),
user_context=body.get("userContext"),
session=session,
Expand Down
18 changes: 18 additions & 0 deletions tests/test-server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ def create_new_session_without_request_response(): # type: ignore

return jsonify(convert_session_to_json(session_container))

@app.route("/test/session/getallsessionhandlesforuser", methods=["POST"]) # type: ignore
def get_all_session_handles_for_user_api(): # type: ignore
data = request.json
if data is None:
return jsonify({"status": "MISSING_DATA_ERROR"})

user_id = data["userId"]
fetch_sessions_for_all_linked_accounts = data.get(
"fetchSessionsForAllLinkedAccounts", True
)
tenant_id = data.get("tenantId", "public")
user_context = data.get("userContext", {})

response = session.get_all_session_handles_for_user(
user_id, fetch_sessions_for_all_linked_accounts, tenant_id, user_context
)
return jsonify(response)

@app.route("/test/session/getsessionwithoutrequestresponse", methods=["POST"]) # type: ignore
def get_session_without_request_response(): # type: ignore
data = request.json
Expand Down
18 changes: 17 additions & 1 deletion tests/test-server/test_functions_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def func(*args): # type: ignore

return func # type: ignore

elif eval_str.startswith("accountlinking.init.onAccountLinked"):

async def on_account_linked(
user: User, recipe_level_user: RecipeLevelUser, user_context: Dict[str, Any]
) -> None:
global primary_user_in_callback
global new_account_info_in_callback
primary_user_in_callback = user
new_account_info_in_callback = recipe_level_user

return on_account_linked

elif eval_str.startswith("emailverification.init.emailDelivery.override"):
from supertokens_python.recipe.emailverification.types import (
EmailDeliveryOverrideInput as EVEmailDeliveryOverrideInput,
Expand Down Expand Up @@ -712,7 +724,11 @@ def to_json(self) -> Dict[str, Any]:
else None
),
"email": self.email,
"newAccountInfoInCallback": self.new_account_info_in_callback,
"newAccountInfoInCallback": (
self.new_account_info_in_callback.to_json()
if self.new_account_info_in_callback is not None
else None
),
"primaryUserInCallback": (
self.primary_user_in_callback.to_json()
if self.primary_user_in_callback is not None
Expand Down

0 comments on commit 3634233

Please sign in to comment.