Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shamique/0cd5a21cdf2244560f09a261cba04e84 to your computer and use it in GitHub Desktop.
Save shamique/0cd5a21cdf2244560f09a261cba04e84 to your computer and use it in GitHub Desktop.
authenticate(email, password) {
return new Promise((resolved, reject) => {
const userPool = new AWSCognito.CognitoUserPool(this._POOL_DATA);
const authDetails = new AWSCognito.AuthenticationDetails({
Username: email,
Password: password
});
const cognitoUser = new AWSCognito.CognitoUser({
Username: email,
Pool: userPool
});
cognitoUser.authenticateUser(authDetails, {
onSuccess: result => {
resolved(result);
},
onFailure: err => {
reject(err);
},
newPasswordRequired: userAttributes => {
// User was signed up by an admin and must provide new
// password and required attributes, if any, to complete
// authentication.
// the api doesn't accept this field back
userAttributes.email = email;
delete userAttributes.email_verified;
cognitoUser.completeNewPasswordChallenge(password, userAttributes, {
onSuccess: function(result) {},
onFailure: function(error) {
reject(error);
}
});
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment