How to use the feathers-hooks-common.iff function in feathers-hooks-common

To help you get started, we’ve selected a few feathers-hooks-common 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 feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
// $ExpectType Hook>
validateSchema({}, ajv);

// $ExpectType Hook>
iffElse(syncTrue, [hook1, hook2], [hook3, hook4]);
// $ExpectType Hook>
iffElse(asyncTrue, [hook1, hook2], [hook3, hook4]);

// $ExpectType IffHook
iff(syncTrue, hook1, hook2);
// $ExpectType IffHook
iff(asyncTrue, hook1, hook2);
// $ExpectType Hook>
iff(syncTrue, hook1, hook2).else(hook3, hook4);
// $ExpectType Hook>
iff(asyncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType IffHook
when(syncTrue, hook1, hook2);
// $ExpectType Hook>
when(syncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType Hook>
unless(asyncTrue, hook1, hook2);
// $ExpectType Hook>
unless(syncTrue, hook1, hook2);

// $ExpectType AsyncContextFunction
some(asyncFalse, asyncTrue, syncTrue);

// $ExpectType AsyncContextFunction
every(asyncTrue, syncTrue);
github feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
});

// $ExpectType Hook>
validateSchema({}, ajv);

// $ExpectType Hook>
iffElse(syncTrue, [hook1, hook2], [hook3, hook4]);
// $ExpectType Hook>
iffElse(asyncTrue, [hook1, hook2], [hook3, hook4]);

// $ExpectType IffHook
iff(syncTrue, hook1, hook2);
// $ExpectType IffHook
iff(asyncTrue, hook1, hook2);
// $ExpectType Hook>
iff(syncTrue, hook1, hook2).else(hook3, hook4);
// $ExpectType Hook>
iff(asyncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType IffHook
when(syncTrue, hook1, hook2);
// $ExpectType Hook>
when(syncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType Hook>
unless(asyncTrue, hook1, hook2);
// $ExpectType Hook>
unless(syncTrue, hook1, hook2);

// $ExpectType AsyncContextFunction
some(asyncFalse, asyncTrue, syncTrue);
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
),
      when(isSingleItem(),
        populate({ schema: badgesSchema }),
        populate({ schema: candosSchema }),
        populate({ schema: userSettingsSchema })
      ),
      thumbnails(thumbnailOptions),
      cleanupPersonalData
    ],
    get: [
      populate({ schema: badgesSchema }),
      populate({ schema: candosSchema }),
      populate({ schema: userSettingsSchema }),
      thumbnails(thumbnailOptions),
      // remove personal data if its not the current authenticated user
      iff(isOwnEntry(false),
        cleanupPersonalData
      ),
      iff(isOwnEntry(),
        populate({ schema: userSettingsPrivateSchema })
      )
    ],
    create: [
      when(isProvider('external'),
        sendVerificationEmail()
      ),
      when(isProvider('external'),
        removeVerification()
      ),
      thumbnails(thumbnailOptions),
      inviteCode.after
    ],
github Human-Connection / API / server / services / comments / comments.hooks.js View on Github external
}
  }
};

const xssFields = ['content', 'contentExcerpt'];

//ToDo: Only let users create comments for contributions they are allowed to
module.exports = {
  before: {
    all: [
      softDelete(),
      xss({ fields: xssFields })
    ],
    find: [
      // We want to deleted comments to show up
      iff(
        hook => hook.params.headers && hook.params.headers.authorization,
        authenticate('jwt')
      ),
      hook => {
        delete hook.params.query.deleted;
        return hook;
      }
    ],
    get: [
      iff(
        hook => hook.params.headers && hook.params.headers.authorization,
        authenticate('jwt')
      )
    ],
    create: [
      authenticate('jwt'),
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
populate({ schema: candosSchema }),
        populate({ schema: userSettingsSchema })
      ),
      thumbnails(thumbnailOptions),
      cleanupPersonalData
    ],
    get: [
      populate({ schema: badgesSchema }),
      populate({ schema: candosSchema }),
      populate({ schema: userSettingsSchema }),
      thumbnails(thumbnailOptions),
      // remove personal data if its not the current authenticated user
      iff(isOwnEntry(false),
        cleanupPersonalData
      ),
      iff(isOwnEntry(),
        populate({ schema: userSettingsPrivateSchema })
      )
    ],
    create: [
      when(isProvider('external'),
        sendVerificationEmail()
      ),
      when(isProvider('external'),
        removeVerification()
      ),
      thumbnails(thumbnailOptions),
      inviteCode.after
    ],
    update: [
      thumbnails(thumbnailOptions)
    ],
github eddyystop / feathers-service-verify-reset / src / index.js View on Github external
return function verifyReset() { // 'function' needed as we use 'this'
    debug('service initialized');
    const app = this;
    const path = 'verifyReset';
    var users;
    var params;

    const isAction = (...args) => hook => args.indexOf(hook.data.action) !== -1;

    app.use(path, {
      before: {
        create: [
          hooks.iff(isAction('password', 'email'), auth.verifyToken()),
          hooks.iff(isAction('password', 'email'), auth.populateUser()),
        ],
      },
      create(data, params1, cb) {
        debug(`service called. action=${data.action}`);
        var callbackCalled = false;
        var promise;
        
        users = app.service('/users'); // here in case users service is configured after verifyReset
        params = params1;

        switch (data.action) {
          case 'unique': // backwards compatible, fall through
          case 'checkUnique':
            promise = checkUniqueness(data.value, data.ownId || null, data.meta || {});
            break;
          case 'resend': // backwards compatible, fall through
github phoomparin / FlipED / src / services / authentication.js View on Github external
console.log("info", "OPTIONS", options)
    }
  }))

  this.configure(local())
  this.configure(jwt())

  this.service("authentication").before({
    create: [
      auth.hooks.authenticate(["jwt", "local"])
    ]
  })

  this.service("authManagement").before({
    create: [
      hooks.iff(
        isAction("passwordChange", "identityChange"),
        auth.hooks.authenticate(["jwt", "local"])
      ),
      hooks.iff(
        isAction("resendVerifySignup", "passwordChange", "identityChange"),
        hooks.populate({
          include: {
            service: "users"
          }
        })
      )
    ]
  })
}
github codingfriend1 / Feathers-Vue / server / services / users / users.hooks.js View on Github external
isEnabled(),
    ],
    create: [ 
      hashPassword(),
      verifyHooks.addVerification(),
      setDefaultRole(),
      setFirstUserToRole({role: 'admin'}),
      preventDisabledAdmin(),
      loopItems(setUserInitials)
    ],
    update: [ 
      commonHooks.disallow('external')
    ],
    patch: [ 
      ...restrict,
      commonHooks.iff(commonHooks.isProvider('external'), commonHooks.preventChanges(
        'email',
        'isVerified',
        'verifyToken',
        'verifyShortToken',
        'verifyExpires',
        'verifyChanges',
        'resetToken',
        'resetShortToken',
        'resetExpires'
      )),
      preventDisabledAdmin(),
      loopItems(setUserInitials)
    ],
    remove: [ 
      ...restrict
    ]
github Human-Connection / API / server / services / contributions / contributions.hooks.js View on Github external
zoom: '0x1024/filters:background_color(fff)',
    cover: '729x300/smart/filters:background_color(fff):upscale()',
    coverPlaceholder: '243x100/smart/filters:blur(30):background_color(fff)'
  }
};

const xssFields = ['content', 'contentExcerpt', 'cando.reason'];

module.exports = {
  before: {
    all: [
      softDelete(),
      xss({fields: xssFields})
    ],
    find: [
      iff(
        hook => hook.params.headers && hook.params.headers.authorization,
        authenticate('jwt')
      ),
      unless(isModerator(),
        excludeDisabled()
      ),
      excludeBlacklisted(),
      when(isProvider('server'),
        includeAll()
      ),
      search(),
      search({
        fields: ['title', 'content']
      })
    ],
    get: [
github phoomparin / FlipED / src / services / authentication.js View on Github external
this.configure(local())
  this.configure(jwt())

  this.service("authentication").before({
    create: [
      auth.hooks.authenticate(["jwt", "local"])
    ]
  })

  this.service("authManagement").before({
    create: [
      hooks.iff(
        isAction("passwordChange", "identityChange"),
        auth.hooks.authenticate(["jwt", "local"])
      ),
      hooks.iff(
        isAction("resendVerifySignup", "passwordChange", "identityChange"),
        hooks.populate({
          include: {
            service: "users"
          }
        })
      )
    ]
  })
}