Cognito - Is it possible to sign up with custom attributes from dropdown ( list of pre-defined values) and radio button menus?

0

I would like to create a login mechanism for my webpage using Cognito. I was trying to create a sign-up form with custom attributes, by creating an User Pool. Though there is option to add custom attributes, I was unable to populate those fields on the SIGN UP form of Cognito-ui. Is there is a way to add custom attributes with dropdown menus and radio buttons from a pre-defined list of values? Happy to share more information if required. Thanks in advance

Gopika
asked 9 months ago607 views
1 Answer
1
Accepted Answer

Yes, it is possible to create a sign-up form with custom attributes using Amazon Cognito. However, the built-in UI for Amazon Cognito does not support dropdown menus or radio buttons out of the box. The custom attributes you add in the User Pool are treated as text fields.

To achieve this, you would need to create a custom UI for your sign-up form. You can use the Amazon Cognito SDK in your application to interact with your User Pool. This way, you can design the form however you like, including adding dropdown menus and radio buttons.

Here's a basic example of how you might use the SDK to sign up a new user with custom attributes:

import boto3

client = boto3.client('cognito-idp')

response = client.sign_up(
    ClientId='YOUR_COGNITO_APP_CLIENT_ID',
    Username='username',
    Password='password',
    UserAttributes=[
        {
            'Name': 'custom:attribute1',
            'Value': 'value1'
        },
        {
            'Name': 'custom:attribute2',
            'Value': 'value2'
        },
    ],
)

In this example, 'custom:attribute1' and 'custom:attribute2' are the custom attributes you've defined in your User Pool, and 'value1' and 'value2' are the values the user has selected or entered in your custom form.

Remember to replace 'YOUR_COGNITO_APP_CLIENT_ID' with your actual Cognito App client ID, and 'username' and 'password' with the user's actual username and password.

This approach gives you full control over the sign-up process, allowing you to implement any form controls you need.

profile picture
answered 9 months ago
  • Thank you @Ercan -flightlesstux-. That really helped. Is there a way we can retrieve user details along with custom attributes in access-token as encrypted on successful login?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions