How to use
#
Use the override config- NodeJS
- GoLang
- Python
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
info
See all the functions that can be overrided here
import SuperTokens from "supertokens-node";
import ThirdPartyPasswordless from "supertokens-node/recipe/thirdpartypasswordless";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
ThirdPartyPasswordless.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/plessmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
thirdpartypasswordless.Init(tplmodels.TypeInput{
Override: &tplmodels.OverrideStruct{
Functions: func(originalImplementation tplmodels.RecipeInterface) tplmodels.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, tenantId string, userContext supertokens.UserContext) (tplmodels.ConsumeCodeResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalConsumeCode(userInput, linkCode, preAuthSessionID, tenantId, 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, InputAppInfo
from supertokens_python.recipe import thirdpartypasswordless
from supertokens_python.recipe.thirdpartypasswordless.interfaces import ConsumeCodeOkResult, ConsumeCodeIncorrectUserInputCodeError, ConsumeCodeExpiredUserInputCodeError, ConsumeCodeRestartFlowError
from supertokens_python.recipe.thirdpartypasswordless.interfaces import RecipeInterface
from typing import Union, Dict, Any
def override_thirdpartypasswordless_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],
tenant_id: str,
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, tenant_id, user_context)
original_implementation.consume_code = consume_code
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
thirdpartypasswordless.init(
contact_config=...,
flow_type="...",
override=thirdpartypasswordless.InputOverrideConfig(
functions=override_thirdpartypasswordless_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.