summaryrefslogtreecommitdiff
path: root/src/hooks/index.js
blob: 2b122bb12c9974b0dc8ab48e87bcdc48acab0d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';

// Add any common hooks you want to share across services in here.
//
// Below is an example of how a hook is written and exported. Please
// see http://docs.feathersjs.com/hooks/readme.html for more details
// on hooks.

const hooks = require('feathers-hooks');
const auth = require('feathers-authentication').hooks;
const or = require('promise-or');

exports.restrictToOwnersOrAdmins = function() {
  var ownerHook = auth.restrictToOwner()
  var adminHook = auth.restrictToRoles({ roles: ["admin"] })
  return function(hook) {
    return or(ownerHook(hook), adminHook(hook))
  };
};