All files / src client.js

88.88% Statements 32/36
62.5% Branches 10/16
100% Functions 13/13
88.88% Lines 32/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108        11x       11x   11x 1x               11x 1x             11x 1x           11x 1x           11x 1x             11x 1x           11x 1x           11x 1x           11x 1x           11x 2x   2x   2x   2x 1x       1x         1x     1x 1x           1x 1x    
 
// Wrapper for client interface to feathers-authenticate-management
 
function AuthManagement (app) { // eslint-disable-line no-unused-vars
  Iif (!(this instanceof AuthManagement)) {
    return new AuthManagement(app);
  }
 
  const authManagement = app.service('authManagement');
 
  this.checkUnique = async (identifyUser, ownId, ifErrMsg) => {
    await authManagement.create({
      action: 'checkUnique',
      value: identifyUser,
      ownId,
      meta: { noErrMsg: ifErrMsg }
    }, {});
  };
 
  this.resendVerifySignup = async (identifyUser, notifierOptions) => {
    await authManagement.create({
      action: 'resendVerifySignup',
      value: identifyUser,
      notifierOptions
    }, {});
  };
 
  this.verifySignupLong = async (verifyToken) => {
    await authManagement.create({
      action: 'verifySignupLong',
      value: verifyToken
    }, {});
  };
 
  this.verifySignupShort = async (verifyShortToken, identifyUser) => {
    await authManagement.create({
      action: 'verifySignupShort',
      value: { user: identifyUser, token: verifyShortToken }
    }, {});
  };
 
  this.sendResetPwd = async (identifyUser, notifierOptions) => {
    await authManagement.create({
      action: 'sendResetPwd',
      value: identifyUser,
      notifierOptions
    }, {});
  };
 
  this.resetPwdLong = async (resetToken, password) => {
    await authManagement.create({
      action: 'resetPwdLong',
      value: { token: resetToken, password }
    }, {});
  };
 
  this.resetPwdShort = async (resetShortToken, identifyUser, password) => {
    await authManagement.create({
      action: 'resetPwdShort',
      value: { user: identifyUser, token: resetShortToken, password }
    }, {});
  };
 
  this.passwordChange = async (oldPassword, password, identifyUser) => {
    await authManagement.create({
      action: 'passwordChange',
      value: { user: identifyUser, oldPassword, password }
    }, {});
  };
 
  this.identityChange = async (password, changesIdentifyUser, identifyUser) => {
    await authManagement.create({
      action: 'identityChange',
      value: { user: identifyUser, password, changes: changesIdentifyUser }
    }, {});
  };
 
  this.authenticate = async (email, password, cb) => {
    let cbCalled = false;
 
    return app.authenticate({ type: 'local', email, password })
      .then(result => {
        const user = result.data;
 
        if (!user || !user.isVerified) {
          app.logout();
          return cb(new Error(user ? 'User\'s email is not verified.' : 'No user returned.'));
        }
 
        Iif (cb) {
          cbCalled = true;
          return cb(null, user);
        }
 
        return user;
      })
      .catch((err) => {
        Eif (!cbCalled) {
          cb(err);
        }
      });
  };
}
 
Eif (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
  module.exports = AuthManagement;
}