rp_st
04/11/2023, 1:59 PMrp_st
04/11/2023, 2:00 PMapi_options
input to the override func:
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import passwordless
from supertokens_python.recipe.passwordless.interfaces import APIInterface, APIOptions, ConsumeCodePostOkResult
from typing import Union, Dict, Any
def override_passwordless_apis(original_implementation: APIInterface):
original_consume_code_post = original_implementation.consume_code_post
async def consume_code_post(pre_auth_session_id: str,
user_input_code: Union[str, None],
device_id: Union[str, None],
link_code: Union[str, None],
api_options: APIOptions,
user_context: Dict[str, Any]):
# Access the custom_field parameter from the user_context dictionary
custom_field = (await api_options.request.json())["custom_field"]
# First we call the original implementation of consume_code_post.
response = await original_consume_code_post(pre_auth_session_id, user_input_code, device_id, link_code, api_options, user_context)
# Post sign up response, we check if it was successful
if isinstance(response, ConsumeCodePostOkResult):
user = response.user
if response.created_new_user:
# TODO: post sign up logic
else:
# TODO: post sign in logic
return response
# Update the original implementation with the new consume_code_post function
original_implementation.consume_code_post = consume_code_post
return original_implementation
init(InputAppInfo(...))
passwordless.init({
"override": {
"apis": override_passwordless_apis
}
})
essentially we use:
custom_field = (await api_options.request.json())["custom_field"]