Skip to content

Authenticator - Allow adding custom fields to SignIn screen #6570

@fmonper1

Description

@fmonper1

On which framework/platform would you like to see this feature implemented?

React

Which UI component is this feature-request for?

Authenticator

Please describe your feature-request in detail.

Im setting up a multi-tenant SaaS that requires using and organizationId in order to login our users.

I've managed to implement a custom organization_id field on the SignUp form using the following code:

    <Authenticator
      services={services({
        inviteCode: invitation || undefined,
        organizationId: organizationId || undefined,
      })}
      initialState={invitation ? 'signUp' : 'signIn'}
      formFields={{
        signUp: {
          username: {
            placeholder: 'Enter Your Email Here',
            isRequired: true,
            label: 'Email:',
          },
          ...(invitation && organizationId
            ? {
                'custom:organization_id': {
                  placeholder: 'Enter your Organization ID here',
                  isRequired: false,
                  label: 'Organization ID',
                  defaultValue: organizationId ?? undefined,
                  isReadOnly: true,
                  order: 1,
                },
              }
            : {}),
        },
      }}

But now I also need to be able to provide the organization_id during the logIn process, so naturally I tried doing the following:

    <Authenticator
      services={services({
        inviteCode: invitation || undefined,
        organizationId: organizationId || undefined,
      })}
      initialState={invitation ? 'signUp' : 'signIn'}
      formFields={{
        signIn: {
          organization_id: {
            placeholder: '(Optional) Enter your Organization ID here',
            isRequired: false,
            label: 'Organization ID',
            order: 1,
          },
          username: {
            placeholder: 'Enter Your Email Here',
            isRequired: true,
            label: 'Email',
          },
        },
      }}

But unfortunately when I implement the handleSignIn function in my service, I never get the value for this custom organization_id field

 async handleSignIn(input: SignInInput) {
      const { username, password, options } = input

      const organizationId =
        options?.userAttributes?.['custom:organization_id'] ||
        options?.clientMetadata?.['custom:organization_id']
      const hashedUsername = getHashedUsername(username, organizationId)

      console.log({ input, organizationId, hashedUsername })

      return signIn({
        username: hashedUsername,
        password,
        options: {
          ...input.options,
          userAttributes: {
            email: username,
          },
        },
      })
    },

Please describe a solution you'd like.

I would like the SignIn form to display custom fields the same way that the SignUp form allows us to add custom userAttributes so that we can build more complex authentication flows.

Alternatively it would be nice to overwrite the components on the SignUp form doing something like:

      components={{
        SignIn: {
          FormFields() {
            // eslint-disable-next-line react-compiler/react-compiler
            const { validationErrors } = useAuthenticator()

            return (
              <>
                <TextField
                  name="organization_id"
                  label="Organization ID"
                  placeholder="Enter your Organization ID here"
                  defaultValue={organizationId ?? undefined}
                />


                <Authenticator.SignIn.FormFields />
              </>
            )
          },
        },

We love contributors! Is this something you'd be interested in working on?

  • 👋 I may be able to implement this feature request.
  • ⚠️ This feature might incur a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthenticatorAn issue or a feature-request for an Authenticator UI Componentfeature-requestRequest a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions