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 EmailPassword from "supertokens-node/recipe/emailpassword";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
EmailPassword.init({
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
// here we are only overriding the function that's responsible
// for signing in a user.
signUp: async function (input) {
// TODO: some custom logic
// or call the default behaviour as show below
return await originalImplementation.signUp(input);
},
// ...
// TODO: override more functions
}
}
}
})
]
});
originalImplementation
is an object that contains 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
signUp
function of this recipe. This function will be used to handle the scenario when the user clicks on the sign up button from 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{
Functions: func(originalImplementation epmodels.RecipeInterface) epmodels.RecipeInterface {
//First we copy the original impl func
originalSignUp := *originalImplementation.SignUp
// Then we override the functions we want to
(*originalImplementation.SignUp) = func(email, password string, userContext supertokens.UserContext) (epmodels.SignUpResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignUp(email, password, userContext)
}
// TODO: Override more functions
return originalImplementation
},
},
}),
},
})
}
originalImplementation
is an object that contains 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
signUp
function of this recipe. This function will be used to handle the scenario when the user clicks on the sign up button from 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 RecipeInterface as EPInterface
from typing import Dict, Any
def override_email_password_functions(original_implementation: EPInterface):
original_sign_up = original_implementation.sign_up
async def sign_up(email: str, password: str, user_context: Dict[str, Any]):
# TODO: custom logic
# or call the default behaviour as show below
return await original_sign_up(email, password, user_context)
original_implementation.sign_up = sign_up
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
emailpassword.init(
override=emailpassword.InputOverrideConfig(
functions=override_email_password_functions,
)
)
]
)
original_implementation
is an object that contains 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
sign_up
function of this recipe. This function will be used to handle the scenario when the user clicks on the sign up button from the frontend.