How to use
Use the override config#
info
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
                    }
                }
            }
        })
    ]
});
- originalImplementationis 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 createNewSessionfunction of this recipe. This can be used to (for example) modifying the session payload when a new session is created.
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{
                    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(userID string, accessTokenPayload, sessionDataInDatabase map[string]interface{}, disableAntiCsrf *bool, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
                            // TODO: some custom logic
                            // or call the default behaviour as show below
                            return originalCreateNewSession(userID, accessTokenPayload, sessionDataInDatabase, disableAntiCsrf, userContext)
                        }
                        return originalImplementation
                    },
                },
            }),
        },
    })
}
- originalImplementationis 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 createNewSessionfunction 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, Optional
def override_session_functions(original_implementation: RecipeInterface):
    original_create_new_session = original_implementation.create_new_session
    async def create_new_session(user_id: str,
                                 access_token_payload: Optional[Dict[str, Any]],
                                 session_data_in_database: Optional[Dict[str, Any]],
                                 disable_anti_csrf: Optional[bool],
                                 user_context: Dict[str, Any],):
        # TODO: custom logic
        # or call the default behaviour as show below
        return await original_create_new_session(user_id, access_token_payload, session_data_in_database, disable_anti_csrf, 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_implementationis 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_sessionfunction of this recipe. This can be used to (for example) modifying the session payload when a new session is created.