question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignUp with Custom Attributes throws errors

See original GitHub issue

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/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
gruckionvitcommented, Nov 22, 2020

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.

5reactions
loganwedwardscommented, May 30, 2019

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' }

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Cognito error "attempted to write unauthorized attribute ...
I am trying to add a custom attribute to my cognito users for hasSubscription, and add/update it during signup and login
Read more >
AWS Cognito & Amplify Auth - Bad, Bugged, Baffling
Each custom attribute can be defined as a string or a number . Each custom attribute cannot be removed or changed once added...
Read more >
Error while Creating custom attribute for Customer
When i insert the field value with admin menu it works. But it doesn't works on customer register. I followed this tutorial: https://store....
Read more >
Troubleshoot custom user attribute errors - Google Support
CATEGORY_NAME doesn't exist. Try refreshing the page. Close and relaunch the Custom Attributes dialog box. ; CATEGORY_NAME has already been created. Close and ......
Read more >
SignUp - Amazon Cognito User Pools - AWS Documentation
For custom attributes, you must prepend the custom: prefix to the attribute ... This exception is thrown when Amazon Cognito encounters an internal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found