Question:
I have created a user in Cognito user pool, using the create user option as shown in the image, and want that user to set a new password on first Log In. For this I am using below given method, as given in the AWS documents
Create User from AWS
cognitouser.completeNewPasswordChallenge()
Below is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//Start: setNewPasswordForAdmin setNewPasswordForAdmin(username: string, password: string) { //Start: Creating new user with username and pool data const adminUserdata = { Username: username, Pool: userpoolAdmin } const adminuser = new CognitoUser(adminUserdata); //End: Creating new user with username and pool data //create attributelist array which will contain all the attributes requried for signing in //these attributes are those attributes, which are selected while creating user pool on aws const attributeList : CognitoUserAttribute[] = []; //form a json object containing Name and Value of attribute used const usernameattribute = { Name:'username', Value: username } //Push list of attributes in the attributeList array attributeList.push(new CognitoUserAttribute(usernameattribute)); console.log(attributeList); const that = this; adminuser.completeNewPasswordChallenge(password, attributeList ,{ onFailure(err){ console.log(err); }, onSuccess(result){ console.log(":::::::: Password change successfull "); that.router.navigate(['']); } }); } //End: setNewPasswordForAdmin |
After executing this I get an error saying,
{code: “SerializationException”, name: “SerializationException”,
message: “Start of structure or map found where not expected.”}
These are the attributes which I have selected in User Pool
List Of Attributes and permissions in user pool
Please help me to solve this.
Answer:
In my case it ended up being malformed data being sent to my resetPassword
helper. The function was looking for three parameters (username
, code
, password
):
1 2 3 4 |
export default function (username, code, password) { … } |
… and I was sending them as an object:
1 2 3 4 5 6 |
yield call(authResetPassword, { code: DOMPurify.sanitize(verificationCode), username: DOMPurify.sanitize(email), password: DOMPurify.sanitize(newPassword), }) |
I just updated the helper and I was all set!
1 2 3 4 |
export default function ({ username, code, password }) { … } |
Just log your data in the setNewPasswordForAdmin
function and I’ll bet you’ll find something awry there.