All files restrict-to-authenticated.js

100% Statements 8/8
80% Branches 8/10
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 161x 1x   4x 4x 4x 1x     3x 1x          
import errors from 'feathers-errors';
import get from 'lodash.get';
 
export default function (options = { entity: 'user' }) {
  return function (hook) {
    if (hook.type !== 'before') {
      throw new Error(`The 'restrictToAuthenticated' hook should only be used as a 'before' hook.`);
    }
 
    if (hook.params.provider && get(hook.params, options.entity) === undefined) {
      throw new errors.NotAuthenticated('You are not authenticated.');
      // TODO (EK): Add debug log to check to see if the user is populated, if the token was verified and warn appropriately
    }
  };
}