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 ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
ThirdPartyEmailPassword.init({
override: {
apis: (originalImplementation) => {
return {
...originalImplementation,
// here we only override the email & password sign up API logic
emailPasswordSignUpPOST: async function (input) {
if (originalImplementation.emailPasswordSignUpPOST === undefined) {
throw Error("Should never come here");
}
// TODO: some pre sign up logic
let response = await originalImplementation.emailPasswordSignUpPOST(input);
if (response.status === "OK") {
// TODO: some post sign up logic
}
return response;
},
// ...
// 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
emailPasswordSignUpPOST
api of this recipe. This api will be used to handle the email password sign up requests.
info
See all the functions that can be overrided here
import (
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"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{
APIs: func(originalImplementation tpepmodels.APIInterface) tpepmodels.APIInterface {
//First we copy the original impl
originalEmailPasswordSignUpPOST := *originalImplementation.EmailPasswordSignUpPOST
// here we only override the email & password sign up API logic
(*originalImplementation.EmailPasswordSignUpPOST) = func(formFields []epmodels.TypeFormField, options epmodels.APIOptions, userContext supertokens.UserContext) (tpepmodels.SignUpPOSTResponse, error) {
// TODO: some pre sign up logic
resp, err := originalEmailPasswordSignUpPOST(formFields, options, userContext)
if err != nil {
return tpepmodels.SignUpPOSTResponse{}, err
}
if resp.OK != nil {
// TODO: some post sign up logic
}
return resp, err
}
// 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
emailPasswordSignUpPOST
api of this recipe. This api will be used to handle the email password sign up requests.
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 APIInterface, ThirdPartyAPIOptions
from supertokens_python.recipe.thirdparty.provider import Provider
from typing import Union, Dict, Any
def override_thirdpartyemailpassword_apis(original_implementation: APIInterface):
original_thirdparty_sign_in_up_post = original_implementation.thirdparty_sign_in_up_post
async def thirdparty_sign_in_up_post(provider: Provider, code: str, redirect_uri: str, client_id: Union[str, None], auth_code_response: Union[Dict[str, Any], None],
api_options: ThirdPartyAPIOptions, user_context: Dict[str, Any]):
# TODO: custom logic
# or call the default behaviour as show below
return await original_thirdparty_sign_in_up_post(provider, code, redirect_uri, client_id, auth_code_response, api_options, user_context)
original_implementation.thirdparty_sign_in_up_post = thirdparty_sign_in_up_post
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
thirdpartyemailpassword.init(
override=thirdpartyemailpassword.InputOverrideConfig(
apis=override_thirdpartyemailpassword_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
thirdparty_sign_in_up_post
api of this recipe. This api will be used to handle the signInUp API route when a user either signs up or signs in.