sejn
sejn

Reputation: 2644

How to fix “A client attempted to write unauthorized attribute” issue in cognito? in react-native custom UI(It works fine with default signUP screen))

I am customizing the UI for signUp screen. I got an error as A client attempted to write unauthorized attribute. Here I have used the attributes as mentioned below.

Note: Before I have used the default screens with the below-mentioned attributes from the aws-amplify-react-native. Now also I have the same attributes, but it failed to signUp.

Attributes:

AuthClass - signUp attrs:', [ { Name: 'name', Value: 'Test' },
  { Name: 'email', Value: '[email protected]' },
  { Name: 'phonenumber', Value: '+XXXXXXX' } ]

Error:

Hub - Dispatching to auth with ', { event: 'signUp_failure',
  data: 
   { code: 'NotAuthorizedException',
     name: 'NotAuthorizedException',
     message: 'A client attempted to write unauthorized attribute' },
  message: '[email protected] failed to signup' }

My custom signup screen

class CustomSignUp expends Component {

signUp = () => {
 const { email, password, phonenumber, userName, lastname, validation } = this.state;
   Auth.signUp({
    username: email,
    password,
    attributes: {
        name: userName,
        email: email,          
        phonenumber: phonenumber,
         // optional - E.164 number convention
        // other custom attributes
    },
    })
    .then(data => console.warn("ddddddddd"+ data))
    .catch(err =>{
      console.warn('errrr' + err)
      validation.messages.push(err.message);
    }
    );

render () {
  return (
   <Button onPress={this.signUp}>SignUP</Button>
 )
}
}

My Authenticator:

<Authenticator>
   <CustomSignUP override={'SignUp'}
</Authenticator>

Upvotes: 0

Views: 2113

Answers (1)

Taliane Tchissambou
Taliane Tchissambou

Reputation: 21

You have to get the right standard/custom attribute name.

You can find the attribute name on the following page:

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#cognito-user-pools-standard-attributes

in your case, phonenumber need to be replaced by phone_number.

Upvotes: 1

Related Questions