How to use
If you would like to change something pre or post our API logic, then use this method.
- 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 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, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignUpPOST(formFields, tenantId, 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, InputAppInfo
from supertokens_python.recipe import emailpassword
from supertokens_python.recipe.emailpassword.interfaces import APIInterface as EmailPasswordAPIInterface, APIOptions as EPAPIOptions
from supertokens_python.recipe.emailpassword.types import FormField
from 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], tenant_id: str,
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, tenant_id, 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.