Create a new Service with casl&Dashboard
const { Service } = require('feathers-mongoose');
exports.Posts = class Posts extends Service {
};const { authenticate } = require('@feathersjs/authentication').hooks;
const { hooks } = require('feathers-mongoose-casl');
const { validateAbilities, validateSchema, sanitizedData } = hooks;
module.exports = {
before: {
all: [
function (hook) {
if (!hook.params.user && hook.params.headers && hook.params.headers.authorization) {
return authenticate('jwt')(hook);
}
else return hook;
}, validateAbilities],
find: [],
get: [],
create: [validateSchema],
update: [validateSchema],
patch: [validateSchema],
remove: []
},
after: {
all: [sanitizedData],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
7. Commit changes
git add .
git commit -m "create posts service"dashboard:
Now you can see the posts service inside the dashboard
https://feathersjs-mongoose-casl-admin.herokuapp.com/
Anyone can read the posts title
User can create/update only if he the author
Only admin user can delete posts
Try to create a new posts from the dashboard
Last updated
Was this helpful?