How to use
#
Use the override config- NodeJS
- GoLang
- Python
info
See all the functions that can be overrided here
import SuperTokens from "supertokens-node";import Passwordless from "supertokens-node/recipe/passwordless";
SuperTokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ contactMethod: "EMAIL", // This example will work with any contactMethod flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", // This example will work with any flow.
override: { functions: (originalImplementation) => { return { ...originalImplementation,
// here we are only overriding the function that's responsible // for signing in / up a user. consumeCode: async function (input) { // TODO: some custom logic
// or call the default behaviour as show below return await originalImplementation.consumeCode(input); }, // ... // TODO: override more functions }; }, } }) ]});
originalImplementation
is an object that contain functions that have the original implementation for this recipe. They can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
consumeCode
function of this recipe. This function will be used to handle the scenario when the user enters an OTP or clicks on a magic link.
info
See all the functions that can be overrided here
import ( "github.com/supertokens/supertokens-golang/recipe/passwordless" "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" "github.com/supertokens/supertokens-golang/supertokens")
func main() { supertokens.Init(supertokens.TypeInput{ RecipeList: []supertokens.Recipe{ passwordless.Init(plessmodels.TypeInput{ Override: &plessmodels.OverrideStruct{ Functions: func(originalImplementation plessmodels.RecipeInterface) plessmodels.RecipeInterface { //First we copy the original impl func originalConsumeCode := *originalImplementation.ConsumeCode
// Then we override the functions we want to (*originalImplementation.ConsumeCode) = func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, userContext supertokens.UserContext) (plessmodels.ConsumeCodeResponse, error) { // TODO: some custom logic
// or call the default behaviour as show below return originalConsumeCode(userInput, linkCode, preAuthSessionID, userContext) }
// TODO: Override more functions
return originalImplementation }, }, }), }, })}
originalImplementation
is an object that contain functions that have the original implementation for this recipe. They can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
ConsumeCode
function of this recipe. This function will be used to handle the scenario when the user enters an OTP or clicks on a magic link.
info
See all the functions that can be overrided here
from supertokens_python import init, InputAppInfofrom supertokens_python.recipe import passwordlessfrom supertokens_python.recipe.passwordless.interfaces import ConsumeCodeOkResult, ConsumeCodeIncorrectUserInputCodeError, ConsumeCodeExpiredUserInputCodeError, ConsumeCodeRestartFlowErrorfrom supertokens_python.recipe.passwordless.interfaces import RecipeInterfacefrom typing import Union, Dict, Any
def override_passwordless_functions(original_implementation: RecipeInterface): original_consume_code = original_implementation.consume_code async def consume_code(pre_auth_session_id: str, user_input_code: Union[str, None], device_id: Union[str, None], link_code: Union[str, None], user_context: Dict[str, Any]) -> Union[ConsumeCodeOkResult, ConsumeCodeIncorrectUserInputCodeError, ConsumeCodeExpiredUserInputCodeError, ConsumeCodeRestartFlowError]: # TODO: some custom logic # or call the default behaviour as show below return await original_consume_code(pre_auth_session_id, user_input_code, device_id, link_code, user_context) original_implementation.consume_code = consume_code return original_implementation
init( app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."), framework='...', recipe_list=[ passwordless.init( contact_config=..., flow_type="...", override=passwordless.InputOverrideConfig( functions=override_passwordless_functions ) ) ])
original_implementation
is an object that contain functions that have the original implementation for this recipe. They can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
consume_code
function of this recipe. This function will be used to handle the scenario when the user enters an OTP or clicks on a magic link.