Guest User

Untitled

a guest
Oct 17th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. authenticate(email, password) {
  2. return new Promise((resolved, reject) => {
  3. const userPool = new AWSCognito.CognitoUserPool(this._POOL_DATA);
  4.  
  5. const authDetails = new AWSCognito.AuthenticationDetails({
  6. Username: email,
  7. Password: password
  8. });
  9.  
  10. const cognitoUser = new AWSCognito.CognitoUser({
  11. Username: email,
  12. Pool: userPool
  13. });
  14.  
  15. cognitoUser.authenticateUser(authDetails, {
  16. onSuccess: result => {
  17. resolved(result);
  18. },
  19. onFailure: err => {
  20. reject(err);
  21. },
  22. newPasswordRequired: userAttributes => {
  23. // User was signed up by an admin and must provide new
  24. // password and required attributes, if any, to complete
  25. // authentication.
  26.  
  27. // the api doesn't accept this field back
  28. userAttributes.email = email;
  29. delete userAttributes.email_verified;
  30.  
  31. cognitoUser.completeNewPasswordChallenge(password, userAttributes, {
  32. onSuccess: function(result) {},
  33. onFailure: function(error) {
  34. reject(error);
  35. }
  36. });
  37. }
  38. });
  39. });
  40. }
Add Comment
Please, Sign In to add comment