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 ThirdParty from "supertokens-node/recipe/thirdparty";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
ThirdParty.init({
signInAndUpFeature: {
providers: [/* ... */]
},
override: {
apis: (originalImplementation) => {
return {
...originalImplementation,
// here we only override the sign in / up API logic
signInUpPOST: async function (input) {
if (originalImplementation.signInUpPOST === undefined) {
throw Error('Should never come here')
}
// TODO: some custom logic
// or call the default behaviour as show below
return await originalImplementation.signInUpPOST(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
signInUpPOST
api of this recipe. This api will be used to handle the signInUp API route when a user either signs up or signs in.
info
See all the functions that can be overrided here
import (
"github.com/supertokens/supertokens-golang/recipe/thirdparty"
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
thirdparty.Init(&tpmodels.TypeInput{
Override: &tpmodels.OverrideStruct{
APIs: func(originalImplementation tpmodels.APIInterface) tpmodels.APIInterface {
//First we copy the original impl
originalSignInUpPOST := *originalImplementation.SignInUpPOST
// Then we override the functions we want to
(*originalImplementation.SignInUpPOST) = func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext *map[string]interface{}) (tpmodels.SignInUpPOSTResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignInUpPOST(provider, input, 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
signInUpPOST
api of this recipe. This api will be used to handle the signInUp API route when a user either signs up or signs in.
info
See all the functions that can be overrided here
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import thirdparty
from supertokens_python.recipe.thirdparty.interfaces import APIInterface, APIOptions
from typing import Union, Dict, Any, Optional
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
from supertokens_python.recipe.session.interfaces import SessionContainer
def override_thirdparty_apis(original_implementation: APIInterface):
original_sign_in_up_post = original_implementation.sign_in_up_post
async def sign_in_up_post(
provider: Provider,
redirect_uri_info: Optional[RedirectUriInfo],
oauth_tokens: Optional[Dict[str, Any]],
session: Optional[SessionContainer],
should_try_linking_with_session_user: Union[bool, None],
tenant_id: str,
api_options: APIOptions,
user_context: Dict[str, Any],
):
# TODO: custom logic
# or call the default behaviour as show below
return await original_sign_in_up_post(
provider,
redirect_uri_info,
oauth_tokens,
session,
should_try_linking_with_session_user,
tenant_id,
api_options,
user_context,
)
original_implementation.sign_in_up_post = sign_in_up_post
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework="...",
recipe_list=[
thirdparty.init(
override=thirdparty.InputOverrideConfig(apis=override_thirdparty_apis),
sign_in_and_up_feature=thirdparty.SignInAndUpFeature(
providers=[
# ...
]
),
)
],
)
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_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.