Last active
October 17, 2018 10:55
-
-
Save shamique/0cd5a21cdf2244560f09a261cba04e84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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