Skip to main content

How to use

Method 1: Pre / Post API logic change:#

If you would like to change something pre or post our API logic, then use this method.

SuperTokens.init({    appInfo: {...},    supertokens: {...},    recipeList: [        ThirdPartyEmailPassword.init({            override: {                apis: (originalImplementation) => {                    return {                        ...originalImplementation,
                        // here we only override the email & password sign up API logic                         emailPasswordSignUpPOST: async function(input) {                            if (originalImplementation.emailPasswordSignUpPOST === undefined) {                                throw Error("Should never come here");                            }
                            // TODO: some pre sign up logic
                            let response = await originalImplementation.emailPasswordSignUpPOST(input);
                            if (response.status === "OK") {                                // TODO: some post sign up logic                            }
                            return response;
                        },                        // ...                        // TODO: override more apis                    }                },                emailVerificationFeature: {                    apis: (originalImplementationEmailVerification) => {                        return {                            ...originalImplementationEmailVerification,                            verifyEmailPOST: async function(input) {                                                                if (originalImplementationEmailVerification.verifyEmailPOST === undefined) {                                    throw Error("Should never come here");                                }                                // TODO: some custom logic
                                // or call the default behaviour as show below                                return await originalImplementationEmailVerification.verifyEmailPOST(input);                            },                            // ...                            // TODO: override more apis                        }                    }                }            }        })    ]});
  • originalImplementation and originalImplementationEmailVerification are objects that contain APIs that have the original implementation for this and the email verification 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 emailPasswordSignUpPOST api of this recipe. This api will be used to handle the email password sign up requests.
  • Likewise, we override the verifyEmailPOST api from the email verification recipe.

Method 2: Change API logic by copy / paste:#

If you need to change our implementation of the API logic you should use this method.

In this example we will be overriding the password reset API.

important

Note that the ThirdPartyEmailPassword recipe APIs will use EmailPassword and ThirdParty recipe API implementations.

Step 1: Copy the API code from the SDK.#

You first need to find the implementation for the API you would like to change in the backend SDK.

  • All the APIs you can override can be found here, copy the name of the function you would like to override.
  • You can find the API code for this recipe here.
  • In this example we want to override the passwordResetPOST API, so we can search for a function with that name in the page mentioned above.
  • Since this API uses EmailPassword recipe's passwordResetPOST API, make sure to copy the code from here

Step 2: Add the API code in the override config.#

Now in the override config instead of calling the original implementation like we did in Method 1 we can paste the passwordResetPOST code we copied earlier and modify it.

SuperTokens.init({    appInfo: {...},    supertokens: {...},    recipeList: [        ThirdPartyEmailPassword.init({            override: {                apis: (originalImplementation) => {                    return {                        ...originalImplementation,
                        passwordResetPOST: async function({formFields, token, options}) {
                            let newPassword = formFields.filter((f) => f.id === "password")[0].value;
                            let response = await options.recipeImplementation.resetPasswordUsingToken({ token, newPassword });
                            return response;                        }                    }                }            }        })    ]});

You can now freely modify any step in the API.