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 ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
ThirdPartyEmailPassword.init({
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
// here we are only overriding the function that's responsible
// for signing in or signing up a user.
thirdPartySignInUp: async function (input) {
// TODO: some custom logic
// or call the default behaviour as show below
return await originalImplementation.thirdPartySignInUp(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
signInUp
function of this recipe. This function will be used to handle the scenario where a user either signs up or signs in via any third party provider or via email and password.
info
See all the functions that can be overrided here
import (
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
thirdpartyemailpassword.Init(&tpepmodels.TypeInput{
Override: &tpepmodels.OverrideStruct{
Functions: func(originalImplementation tpepmodels.RecipeInterface) tpepmodels.RecipeInterface {
//First we copy the original impl
originalSignInUp := *originalImplementation.ThirdPartySignInUp
// Then we override the functions we want to
(*originalImplementation.ThirdPartySignInUp) = func(thirdPartyID string, thirdPartyUserID string, email string, oAuthTokens map[string]interface{}, rawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider, tenantId string, userContext *map[string]interface{}) (tpepmodels.SignInUpResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignInUp(thirdPartyID, thirdPartyUserID, email, oAuthTokens, rawUserInfoFromProvider, tenantId, 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
signInUp
function of this recipe. This function will be used to handle the scenario where a user either signs up or signs in via any third party provider or via email and password.
info
See all the functions that can be overrided here
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import thirdpartyemailpassword
from supertokens_python.recipe.thirdpartyemailpassword.interfaces import RecipeInterface
from supertokens_python.recipe.thirdparty.types import RawUserInfoFromProvider
from typing import Dict, Any
def override_thirdpartyemailpassword_functions(original_implementation: RecipeInterface):
original_sign_in_up = original_implementation.thirdparty_sign_in_up
async def sign_in_up(
third_party_id: str,
third_party_user_id: str,
email: str,
oauth_tokens: Dict[str, Any],
raw_user_info_from_provider: RawUserInfoFromProvider,
tenant_id: str,
user_context: Dict[str, Any]
):
# TODO: custom logic
# or call the default behaviour as show below
return await original_sign_in_up(third_party_id, third_party_user_id, email, oauth_tokens, raw_user_info_from_provider, tenant_id, user_context)
original_implementation.thirdparty_sign_in_up = sign_in_up
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
thirdpartyemailpassword.init(
override=thirdpartyemailpassword.InputOverrideConfig(
functions=override_thirdpartyemailpassword_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_in_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.