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 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, code string, authCodeResponse interface{}, redirectURI string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.SignInUpPOSTResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignInUpPOST(provider, code, authCodeResponse, redirectURI, 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
from supertokens_python.recipe.thirdparty.provider import Provider
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, code: str, redirect_uri: str, client_id: Union[str, None], auth_code_response: Union[Dict[str, Any], None], 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, code, redirect_uri, client_id, auth_code_response, 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.