Skip to main content

Adding Extra Fields

Step 1: Front End#

Currently, your Sign-up form contains only email and password fields. But you might want to get more information from your customers on sign up. Let's see how you can extend the Sign-up form to fit your needs.

SuperTokens.init({    appInfo: {...},    recipeList: [        EmailPassword.init({            signInAndUpFeature: {                signUpForm: {                    formFields: [{                        id: "name",                        label: "Full name",                        placeholder: "First name and last name"                    }, {                        id: "age",                        label: "Your age",                        placeholder: "How old are you?",                    }, {                        id: "country",                        label: "Your country",                        placeholder: "Where do you live?",                        optional: true                    }]                }            }        }),        Session.init()    ]});

Step 2: Back End#

Add fields to SuperTokens init#

Now that you have added new fields to the front end you need to make sure that the backend will take them into account when your new users register.

Go back to where you have called the SuperTokens init function in your backend application:

SuperTokens.init({    appInfo: {...},    supertokens: {...},    recipeList: [        EmailPassword.init({            signUpFeature: {                formFields: [{                  id: "name"                }, {                  id: "age"                }, {                  id: "country",                  optional: true                }]            }        }),        Session.init({...})    ]});

Handle form fields on successful Sign-up#

To handle form fields on the backend you'll have to override the signUpPOST API when initializing the recipe:

SuperTokens.init({    appInfo: {...},    supertokens: {...},    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") {
                                // These are the input form fields values that the user used while signing up                                let formFields = input.formFields;                                                            }                            return response;                        }                    }                }            }        }),        Session.init({...})    ]});

SuperTokens does not store custom form fields. You need to store them in your db post user sign up.