I am banging my head on the wall trying to figure this one out. I have the code below in my react app. I needed to add some way for the user to add a unit/apt number, so I added a custom attribute.
Everything works, but when I include apt_number: this.state.unitNumber,
I get the error {code: "NotAuthorizedException", name: "NotAuthorizedException", message: "A client attempted to write unauthorized attribute"}
.
I did go into my settings and make the attributes writable (I tried both with an attribute of Unit
and apt number
)
Here is my code:
const receivedNewUser = await Auth.signUp({
username: this.state.email,
password: this.state.password,
attributes: {
phone_number: this.state.phone,
address: this.state.streetAddress,
birthdate: this.state.dob,
locale: this.state.zipCode,
given_name: this.state.fname,
family_name: this.state.lname,
apt_number: this.state.unitNumber,
},
});
What is going on?
You need to add custom:
as a prefix to the attribute name.
Your code should read:
const receivedNewUser = await Auth.signUp({
username: this.state.email,
password: this.state.password,
attributes: {
phone_number: this.state.phone,
address: this.state.streetAddress,
birthdate: this.state.dob,
locale: this.state.zipCode,
given_name: this.state.fname,
family_name: this.state.lname,
'custom:apt_number': this.state.unitNumber,
},
});