SuperTokens

SuperTokens

  • Docs
  • Discord
  • Blog

โ€บSign Up Form

SIDEBAR_REPLACE_DOC_Introduction

  • Introduction

Quick setup

  • Video tutorial & Architecture
  • Frontend
  • Backend
  • Core

    • Core Overview
    • Self Hosted setup with Docker
    • Self Hosted setup without Docker
    • Managed Service

    Database Setup

    • MySQL
    • PostgreSQL

Common customizations

  • Sign Out
  • Sign Up Form

    • About
    • Adding Extra Fields
    • Adding / Modifying field validators
    • Embed in a page
    • Handling signup success
    • Terms of service & Privacy policy links

    Sign In Form

    • About
    • Adding / Modifying field validators
    • Password managers
    • Embed in a page
    • Show Sign In by default

    Reset Password

    • About
    • Reset password email
    • Embed in a page

    Email Verification

    • About
    • Customising the email sent
    • Embed in a page

    Sessions

    • About
    • Cookie Consent
    • Creating a new session
    • Session Verification in API
    • Change session timeout
    • Checking if a session exists on the frontend
    • Get user information on the frontend
    • Using with FaunaDB

    Styling

    • Changing Colours
    • Changing Style via CSS
    • Themes

    Changing base path

    • Website Base Path
    • API Base Path

    Multi Tenancy

    • About
    • One login, many sub domains
    • One login per sub domain
  • User Pagination

Advanced users

    Advanced session management

    • Share sessions across sub domains
    • Anti CSRF
    • JWT Signing key rotation
    • Access token blacklisting
    • Customizing Error Handling

    Supertokens Core config

    • Adding API Keys
    • Tuning Performance
    • Logging
    • Rename database tables

    Make your own frontend

    • Sign-up / Sign-in custom theme
    • Reset password custom theme

    Make your own backend

    • Sign up custom API
    • Sign in custom API
    • Reset password custom APIs

NextJS

  • SuperTokens with NextJS
  • Deploy with Vercel
  • Deploy with Netlify

SIDEBAR_REPLACE_DOC_SDKs

  • SDKs

SIDEBAR_REPLACE_DOC_Compatibility Table

  • Compatibility Table

Migration

  • Migrating from an older version of SuperTokens
  • Migrating to SuperTokens
  • Migrating away from SuperTokens
  • From managed service to self hosted

Adding Extra Fields ๐Ÿ’ฅ

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()
    ]
});

Please refer to the auth-react reference API for more information about adding custom fields.

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 NodeJs 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

Supertokens does not store those custom fields on successful signup.

Instead, you should use the handleCustomFormFieldsPostSignUp callback to handle those values yourselves.

SuperTokens.init({
    appInfo: {...},
    supertokens: {...},
    recipeList: [
        EmailPassword.init({
            signUpFeature: {
                formFields: [{
                  id: "name"
                }, {
                  id: "age"
                }, {
                  id: "country",
                  optional: true
                }],
                handleCustomFormFieldsPostSignUp: async (user, formFields) => {
                    let {id, email} = user;
                    /* formFields is [
                        {id: "name", value: "..."},
                        {id: "age", value: ...},
                        {id: "country", value: "..." or "" if not provided}
                       ] 
                    */
                    // TODO: Sanitize form fields and store in your DB.
                }
            } 
        }),
        Session.init({...})
    ]
});
Please note that Supertokens is not applying any processing to those custom fields. That means you should sanitize all the fields.

Please refer to the NodeJS reference API for more information on handleCustomFormFieldsPostSignUp input types.

โ† AboutAdding / Modifying field validators โ†’