In Feathers the goal is to restrict the data accessible on a certain service to the data owned by the currently logged in user only.
Assuming that I am using Feathers authentication, the data available on this service is stored in a database table, and the table column that contains the user ID is called user_id, will this hook achieve the goal?
If not then what needs to change?
In case it is important to be able to answer the question then I am using Sequelize and Postgres.
const { authenticate } = require('feathers-authentication').hooks;
const { queryWithCurrentUser } = require('feathers-authentication-hooks');
const { associateCurrentUser } = require('feathers-authentication-hooks');
const readRestrict = [
  queryWithCurrentUser({
    idField: 'id',
    as: 'user_id'
  })
];
const modRestrict = [
  associateCurrentUser({
    idField: 'id',
    as: 'user_id'
  })
];
module.exports = {
  before: {
    all:    [ authenticate('jwt') ],
    find:   [ ...readRestrict ],
    get:    [ ...readRestrict ],
    create: [ ...modRestrict ],
    update: [ ...modRestrict ],
    patch:  [ ...modRestrict ],
    remove: [ ...modRestrict ]
  },
  after: {
    all:    [],
    find:   [],
    get:    [],
    create: [],
    update: [],
    patch:  [],
    remove: []
  },
  error: {
    all:    [],
    find:   [],
    get:    [],
    create: [],
    update: [],
    patch:  [],
    remove: []
  }
};
It seems to work but since I'm a Feathers noob I thought I'd better check before this is put into the wild to make sure there are no cases that I am unaware of that will cause leaks.
 
    