Create a new Service with casl&Dashboard
1 - Create new service
feathers generate service
? What kind of service is it? Mongoose
? What is the name of the service? posts
? Which path should the service be registered on? /posts
? Does the service require authentication? Yes 2. Create Validator file
const {Joi} = require('feathers-mongoose-casl');
const getJoiObject = function(withRequired){
const required = withRequired ? 'required' : 'optional';
return Joi.object({
author: Joi.objectId().meta({
type: 'ObjectId',
ref: 'users',
displayKey: 'email'
})[required](),
title: Joi.string().min(5)[required]().meta({
dashboard: {
label: 'Post title',
inputProps: JSON.stringify({style: {background: 'red'}})
}
}),
body: Joi.string()[required](),
rating: Joi.number().max(5).meta({
dashboard: {
hideOnUpdate: true,
hideOnCreate: true,
}
}),
image: Joi.objectId().meta({
type: 'ObjectId',
ref: 'files',
displayKey: 'name'
})
});
};
module.exports = getJoiObject;3. Update Posts model
Mongoose schema4. Define abilities and config dashboard
6. Protect posts.hooks
7. Commit changes
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?