Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- });
- }
- });
- });
- }
Add Comment
Please, Sign In to add comment