How to use the amazon-cognito-identity-js.CognitoUser.prototype function in amazon-cognito-identity-js

To help you get started, we’ve selected a few amazon-cognito-identity-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github isotoma / react-cognito / test / auth.js View on Github external
case 'success':
    case 'email-verification-required':
      callback();
      break;
    default:
      assert(false, 'unrecognised username in credentials refresh');
  }
});

const mockSession = {
  getIdToken: () => ({
    getJwtToken: () => 'jwt_token',
  }),
};

sinon.stub(CognitoUser.prototype, 'getAttributeVerificationCode').callsFake((attribute, callbacks) =>
  callbacks.inputVerificationCode(),
);

sinon.stub(CognitoUser.prototype, 'getUserAttributes').callsFake(function f(callback) {
  const verified = this.username === 'email-verification-required' ? 'false' : 'true';
  callback(undefined, [{
    getName: () => 'email_verified',
    getValue: () => verified,
  }]);
});

sinon.stub(CognitoUser.prototype, 'getSession').callsFake(function f(callback) {
  switch (this.username) {
    case 'session-error':
      callback(true, null);
      break;
github isotoma / react-cognito / test / auth.js View on Github external
sinon.stub(CognitoUser.prototype, 'getSession').callsFake(function f(callback) {
  switch (this.username) {
    case 'session-error':
      callback(true, null);
      break;
    case 'success':
    case 'email-verification-required':
      callback(false, mockSession);
      break;
    default:
      assert(false, 'unrecognised username in getSession stub');
  }
});

sinon.stub(CognitoUser.prototype, 'authenticateUser').callsFake((creds, f) => {
  switch (creds.username) {
    case 'success':
    case 'session-error':
    case 'email-verification-required':
      f.onSuccess();
      break;
    case 'failure-bad-creds':
      f.onFailure({ code: 'NotAuthorizedException' });
      break;
    case 'failure-not-confirmed':
      f.onFailure({ code: 'UserNotConfirmedException' });
      break;
    case 'mfa':
      f.mfaRequired();
      break;
    case 'newpass':