Trying to make feathers-casl to work with Feathers v5 Dove #117
Replies: 2 comments 3 replies
-
In abilities.ts , user.role is undefined. While user.roleId is valid. Tested by setting breakpoint and use postmen to simulate login (i.e. POST to authentication service). Basicly user.role.name is where I am stuck now.
Looks like no relationship between users table and roles table. Looks like no relationship between users table and roles table. Eventhough users table is setup correctly. Perhaps I am missing something on knex?
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the thorough explanation! Of course You need to populate // hooks for service '/users'
import { alterItems } from "feathers-hooks-common";
const populateRole = () => {
return alterItems(async (user, context) => {
if (!user.roleId) {
return;
}
user.role = await context.app.service('roles' /* YOUR ROLES SERVICEPATH */).get(user.roleId);
return user;
});
}
// ...
// add as after hook
// ... whereever your users hooks live
after: {
all: [populateRole()],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: [],
}, Please let me know if |
Beta Was this translation helpful? Give feedback.
-
I am trying feathers-casl with v5 base on Getting started guide.
Initially I asked question in discord about where to put code to assign the ability by calling defineAbilitiesFor() since authentication.hooks.ts no longger exist in v5.
A repo for my codes is here => https://github.com/HarisHashim/fcasl-example
I solved that by adding the hook in authentication.ts like so
This make feathers-casl work but still does not allow user with admin role to create another user. basically there is after and before hook in users.ts file that use authorizeHook as per bellow code
If authorizeHook is removed from before and after create hook. I can crate another user using admin role. Otherwise I will get below error. Which is how I know that feathers-casl is somewhat working.
The thing is that, I need to allow admin user to create user.
My code for abilities.ts is
Also there are migration and seed file in the repo that create correct database structure since my theory about why it doesn't work is knex and database related. But when there are proper table for user and roles. It still doesn't work.
@fratzinger please help?
Beta Was this translation helpful? Give feedback.
All reactions