How to use
If you would like to change something pre or post our API logic, then use this method.
- NodeJS
- GoLang
- Python
info
See all the functions that can be overrided here
import SuperTokens from "supertokens-node";import EmailPassword from "supertokens-node/recipe/emailpassword";
SuperTokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, supertokens: { connectionURI: "...", }, recipeList: [ EmailPassword.init({ override: { apis: (originalImplementation) => { return { ...originalImplementation,
// here we only override the sign up API logic signUpPOST: async function (input) {
if (originalImplementation.signUpPOST === undefined) { throw Error("Should never come here") } // TODO: some custom logic
// or call the default behaviour as show below return await originalImplementation.signUpPOST(input); }, // ... // TODO: override more apis } } } }) ]});
originalImplementation
is an object that contains apis that have the original implementation for this recipe. They can be used in your custom apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
signUpPOST
api of this recipe. This api will be called when the user clicks the sign up button on the frontend.
info
See all the functions that can be overrided here
import ( "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/supertokens")
func main() { supertokens.Init(supertokens.TypeInput{ RecipeList: []supertokens.Recipe{ emailpassword.Init(&epmodels.TypeInput{ Override: &epmodels.OverrideStruct{ APIs: func(originalImplementation epmodels.APIInterface) epmodels.APIInterface {
//First we copy the original impl function originalSignUpPOST := *originalImplementation.SignUpPOST
// Then we override the functions we want to (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { // TODO: some custom logic
// or call the default behaviour as show below return originalSignUpPOST(formFields, options, userContext) }
// TODO: Override more APIs
return originalImplementation }, }, }), }, })}
originalImplementation
is an object that contains apis that have the original implementation for this recipe. They can be used in your custom apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
signUpPOST
api of this recipe. This api will be called when the user clicks the sign up button on the frontend.
info
See all the functions that can be overrided here
from supertokens_python import init, InputAppInfofrom supertokens_python.recipe import emailpasswordfrom supertokens_python.recipe.emailpassword.interfaces import APIInterface as EmailPasswordAPIInterface, APIOptions as EPAPIOptionsfrom supertokens_python.recipe.emailpassword.types import FormFieldfrom typing import List, Dict, Any
def override_email_password_apis(original_implementation: EmailPasswordAPIInterface): original_sign_up_post = original_implementation.sign_up_post
async def sign_up_post(form_fields: List[FormField], api_options: EPAPIOptions, user_context: Dict[str, Any]): # TODO: custom logic
# or call the default behaviour as show below return await original_sign_up_post(form_fields, api_options, user_context)
original_implementation.sign_up_post = sign_up_post return original_implementation
init( app_info=InputAppInfo( api_domain="...", app_name="...", website_domain="..."),
framework='...', recipe_list=[ emailpassword.init( override=emailpassword.InputOverrideConfig( apis=override_email_password_apis ) ) ])
original_implementation
is an object that contains apis that have the original implementation for this recipe. They can be used in your custom apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
sign_up_post
api of this recipe. This api will be called when the user clicks the sign up button on the frontend.