Skip to main content

How to use

import SuperTokens from "supertokens-node";import Passwordless from "supertokens-node/recipe/passwordless";
SuperTokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "..."    },    recipeList: [        Passwordless.init({            contactMethod: "EMAIL", // This example will work with any contactMethod            createAndSendCustomEmail: async (input) => console.log(input),            flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", // This example will work with any flow.            override: {                apis: (originalImplementation) => {                    return {                        ...originalImplementation,
                        // here we only override the API that is called when a user                        // clicks on a magic link or enters an OTP                        consumeCodePOST: async function (input) {                            if (originalImplementation.consumeCodePOST === undefined) {                                throw Error("Should never come here")                            }
                            // TODO: some custom logic
                            // or call the default behaviour as show below                            return await originalImplementation.consumeCodePOST(input);                        },                        // ...                        // TODO: override more apis                    };                },            },        })    ]});
  • originalImplementation is an object that contain 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 consumeCodePOST api of this recipe. This api will be called when the user clicks on a magic link or enters an OTP.