Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignUp with Custom Attributes throws errors #2958

Closed
rossgeesman opened this issue Mar 29, 2019 · 6 comments
Closed

SignUp with Custom Attributes throws errors #2958

rossgeesman opened this issue Mar 29, 2019 · 6 comments
Labels
Auth Related to Auth components/category question General question

Comments

@rossgeesman
Copy link

rossgeesman commented Mar 29, 2019

Describe the bug
I have created a Cognito User Pool and Identity Pool via Cloud Formation templates using the Serverless Framework. The schema looks like this:

      Schema:
        - Name: family_name
          AttributeDataType: String
          Mutable: true
          Required: true
        - Name: given_name
          AttributeDataType: String
          Mutable: true
          Required: true
        - Name: confirmed_email
          AttributeDataType: Boolean
          Mutable: true
          Required: false

Signup was working fine until I added the confirmed_email attribute and added it to signup. This results in a SerializationException being raised. The only way I can create the user with the custom attribute is to append custom to the key so that confirmed_email becomes custom:confirmed_email and the boolean will only work as a string.

To Reproduce

  1. Use above schema to add attributes to a Cognito User Pool. Then attempt to sign up a user with the following:
Auth.signUp({
      username: email,
      password: password,
      attributes: {
        given_name: given_name,
        family_name: family_name,
        confirmed_email: false
      },
 })
  1. This will result in the following error:
{code: "SerializationException", name: "SerializationException", message: "class java.lang.Boolean can not be converted to an String"}
  1. Now sign up a user with this code:
Auth.signUp({
      username: email,
      password: password,
      attributes: {
        given_name: given_name,
        family_name: family_name,
       'custom: confirmed_email': 'false'
      },
 })

You should not observe the error and the user should be created successfully.

Expected behavior
I expect Auth.signUp() to accept custom attributes as a regular javascript object as shown here: https://aws.amazon.com/blogs/mobile/aws-amplify-adds-support-for-custom-attributes-in-amazon-cognito-user-pools/

@peetss
Copy link

peetss commented Mar 29, 2019

Custom attributes can only be defined as a string or a number, from: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-custom-attributes

@powerful23 powerful23 added Auth Related to Auth components/category question General question pending-close-response-required labels Mar 29, 2019
@haverchuck
Copy link
Contributor

Closing this issue as it appears to have been answered.

@loganwedwards
Copy link

I ran into the same issue (SerializationException), although my value is defined as a Number in the Cognito console, but I had to wrap it in quotes within my app. This is confusing and it the error message is somewhat helpful in retrospect, but not at all intuitive.

My custom attribute is called onboarding with a type of Number. The Cognito console renamed it to custom:onboarding.

In my sign up method, I add:
attributes: { 'custom:onboarding': '0' }

@gruckionvit
Copy link

So what if we add a Boolean custom attribute to our cloudformation schema then realise that only String and Number are supported?

We can't delete the attribute.
We can't modify the attribute.

I want to convert this into a string or remove it. It's broken my authentication flow and there doesn't appear to be a solution to fix this. Am I supposed to delete my amplify backend infrastructure and then amplify push from new?

This is a little nutty if that is the only solution.

@bobbyhadz
Copy link

bobbyhadz commented Feb 5, 2021

This is so confusing, you can define boolean attributes i.e. in cdk:

customAttributes: {
  isAdmin: new cognito.BooleanAttribute({mutable: true}),
},

But custom attributes can only be string or number.

Edit: you can't use number as a custom attribute either: they are still strings, all cognito provides is they try to parse your input and if it's not a number they throw, however the attribute itself is a string.

custom-attr-type-number

custom-attribute-number-string

All throughout your application you have to remember to parse the string into a number, it's more trouble than it's worth, I wish they would've just said they only supports strings.

You can't remove or change the custom attributes either, so once you find out how confusing this behavior is you can't do anything.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Auth Related to Auth components/category question General question
Projects
None yet
Development

No branches or pull requests

7 participants