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 Session from "supertokens-node/recipe/session";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
Session.init({
override: {
apis: (originalImplementation) => {
return {
...originalImplementation,
// here we are only overriding the function that signs out a user
signOutPOST: async function (input) {
if (originalImplementation.signOutPOST === undefined) {
throw Error("Should never come here")
}
// TODO: some custom logic
// or call the default behaviour as show below
return await originalImplementation.signOutPOST(input);
},
// ...
// TODO: override more apis
}
}
}
})
]
});
originalImplementation
is the object that contains apis that have the original implementation for this recipe. It can be used in your apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
signOutPOST
api of this recipe.
info
See all the functions that can be overrided here
import (
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
session.Init(&sessmodels.TypeInput{
Override: &sessmodels.OverrideStruct{
APIs: func(originalImplementation sessmodels.APIInterface) sessmodels.APIInterface {
// First we make a copy of the original implementation
originalSignOutPOST := *originalImplementation.SignOutPOST
// Then we override the default impl
(*originalImplementation.SignOutPOST) = func(sessionContainer sessmodels.SessionContainer, options sessmodels.APIOptions, userContext supertokens.UserContext) (sessmodels.SignOutPOSTResponse, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalSignOutPOST(sessionContainer, options, userContext)
}
return originalImplementation
},
},
}),
},
})
}
originalImplementation
is the object that contains apis that have the original implementation for this recipe. It can be used in your apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
signOutPOST
api of this recipe.
info
See all the functions that can be overrided here
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import session
from supertokens_python.recipe.session.interfaces import APIInterface, APIOptions
from typing import Dict, Any
def override_session_apis(original_implementation: APIInterface):
original_signout_post = original_implementation.signout_post
async def signout_post(
session: session.SessionContainer,
api_options: APIOptions,
user_context: Dict[str, Any],
):
# TODO: custom logic
# or call the default behaviour as show below
return await original_signout_post(session, api_options, user_context)
original_implementation.signout_post = signout_post
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework="...",
recipe_list=[
session.init(
override=session.InputOverrideConfig(apis=override_session_apis)
)
],
)
original_implementation
is the object that contains apis that have the original implementation for this recipe. It can be used in your apis as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
sign_out_post
api of this recipe.