Skip to main content

Post sign up callbacks

There are three customizations that can be done post sign up:

  • 1) Redirecting the user to a specific URL
  • 2) Handling the sign up event on the frontend (for example for analytics)
  • 3) Handling the sign up event on the backend (for example for analytics)

1) Redirecting the user to a specific URL#

SuperTokens.init({    appInfo: {...},    recipeList: [        EmailPassword.init({            getRedirectionURL: async (context) => {                if (context.action === "SUCCESS" && context.isNewUser) {                    if (context.redirectToPath !== undefined) {                        // we are navigating back to where the user was before they authenticated                        return context.redirectToPath;                    }                    return "/dashboard";                }                return undefined;            }        }),        Session.init()    ]});

The user will be redirected to the provided URL on:

  • Successful sign up
  • Successful sign in
  • Successful email verification.
  • If the user is already logged in.
info

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

2) Handling sign up event 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.

SuperTokens.init({    appInfo: {...},    recipeList: [        EmailPassword.init({            onHandleEvent: async (context) => {                if (context.action === "SESSION_ALREADY_EXISTS") {                    // TODO:                } else {                    let {id, email} = context.user;                    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.

3) Handling sign up event on the backend#

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

// backendSuperTokens.init({    appInfo: {...},    supertokens: {...},    recipeList: [        EmailPassword.init({            override: {                apis: (originalImplementation) => {                    return {                        ...originalImplementation,                        signUpPOST: async (input) => {                            // 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({...})    ]});