feathersjs-ecosystem / authentication-local

[MOVED] Local authentication plugin for feathers-authentication
https://github.com/feathersjs/feathers
MIT License
26 stars 15 forks source link

Protect - fields name can contain a regular expression #69

Closed andreas4all closed 6 years ago

andreas4all commented 6 years ago

Fields name can contain a regular expression. No open issue for this. No depends PR.

daffl commented 6 years ago

Thank you for the pull request! This is a good idea. I am wondering if we could make this a little easier using Lodash _.omitBy.

andreas4all commented 6 years ago

I tried to refactored with omitBy, but I have problem with nested object. Can you help me with that?

daffl commented 6 years ago

I was thinking something like:

module.exports = function (...fields) {
  const regExps = fields.filter(isRegExp);
  const fieldNames = fields.filter(field => !isRegExp(field));
  const omitRegex = (value, key) => regExps.some(r => r.test(key));

  return function protect (context) {
    // ...
    const omitted = omit(data, fieldNames);
    // For performance reasons only omit when there are regular expressions
    return regExps.length ? omitBy(omitted, omitRegex) : omitted;
  }
}
daffl commented 6 years ago

Thanks again for the PR @andreas4all. I am going to close this one for now since this repository will be moved into a monorepo at https://github.com/feathersjs/feathers and I haven't heard back about the changes I proposed.

If you are still interested in getting this in, please reopen the pull request there.