Skip to main content

Post sign up callbacks

1) On the frontend#

This method allows you to fire events immediately after a successful sign up. For example to send analytics events post sign up.

import SuperTokens from "supertokens-auth-react";import EmailPassword from "supertokens-auth-react/recipe/emailpassword";import Session from "supertokens-auth-react/recipe/session";
SuperTokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "..."    },    recipeList: [        EmailPassword.init({            onHandleEvent: async (context) => {                if (context.action === "SESSION_ALREADY_EXISTS") {                    // TODO:                } else {                    if (context.action === "SUCCESS") {                        if (context.isNewUser) {                            // TODO: Sign up                        } else {                            // TODO: Sign in                        }                    }                }            }        }),        Session.init()    ]});
info

Please refer to this page to learn more about the onHandleEvent hook.

2) On the backend#

For this, you'll have to override the signUpPOST API in the init function call..

import SuperTokens from "supertokens-node";import EmailPassword from "supertokens-node/recipe/emailpassword";import Session from "supertokens-node/recipe/session";
// backendSuperTokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "..."    },    supertokens: {        connectionURI: "...",    },    recipeList: [        EmailPassword.init({            override: {                apis: (originalImplementation) => {                    return {                        ...originalImplementation,                        signUpPOST: async function (input) {
                            if (originalImplementation.signUpPOST === undefined) {                                throw Error("Should never come here");                            }
                            // First we call the original implementation of signUpPOST.                            let response = await originalImplementation.signUpPOST(input);
                            // Post sign up response, we check if it was successful                            if (response.status === "OK") {                                let { id, email } = response.user;
                                // // These are the input form fields values that the user used while signing up                                let formFields = input.formFields;                                // TODO: post sign up logic                            }                            return response;                        }                    }                }            }        }),        Session.init({ /* ... */ })    ]});

Using the code above, you can (for example):

  • Add the user's ID and their info to your own database (in addition to it being stored in SuperTokens).
  • Send analytics events about a sign up.
  • Send a welcome email to the user.
Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react