How to use
#
Use the override configinfo
See all the functions that can be overrided here
- NodeJS
- GoLang
- Python
import SuperTokens from "supertokens-node";
import Session from "supertokens-node/recipe/session";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
Session.init({
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
// here we are only overriding the function that's responsible
// for creating a new session
createNewSession: async function (input) {
// TODO: some custom logic
// or call the default behaviour as show below
return await originalImplementation.createNewSession(input);
},
// ...
// TODO: override more functions
}
}
}
})
]
});
originalImplementation
is the object that contains functions that have the original implementaion for this recipe. It can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
createNewSession
function of this recipe. This can be used to (for example) modifying the session payload when a new session is created.
import (
"net/http"
"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{
Functions: func(originalImplementation sessmodels.RecipeInterface) sessmodels.RecipeInterface {
// First we make a copy of the original implementation
originalCreateNewSession := *originalImplementation.CreateNewSession
// Then we override the default impl
(*originalImplementation.CreateNewSession) = func(res http.ResponseWriter, userID string, accessTokenPayload, sessionData map[string]interface{}, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
// TODO: some custom logic
// or call the default behaviour as show below
return originalCreateNewSession(res, userID, accessTokenPayload, sessionData, userContext)
}
return originalImplementation
},
},
}),
},
})
}
originalImplementation
is the object that contains functions that have the original implementaion for this recipe. It can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
createNewSession
function of this recipe. This can be used to (for example) modifying the session payload when a new session is created.
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 RecipeInterface
from typing import Any, Dict, Union
def override_session_functions(original_implementation: RecipeInterface):
original_create_new_session = original_implementation.create_new_session
async def create_new_session(request: Any, user_id: str,
access_token_payload: Union[None, Dict[str, Any]],
session_data: Union[None, Dict[str, Any]], user_context: Dict[str, Any]):
# TODO: custom logic
# or call the default behaviour as show below
return await original_create_new_session(request, user_id, access_token_payload, session_data, user_context)
original_implementation.create_new_session = create_new_session
return original_implementation
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
session.init(
override=session.InputOverrideConfig(
functions=override_session_functions
)
)
]
)
original_implementation
is the object that contains functions that have the original implementaion for this recipe. It can be used in your functions as a way to use the SuperTokens' default behaviour.- In the above code snippet, we override the
create_new_session
function of this recipe. This can be used to (for example) modifying the session payload when a new session is created.