CASL authorisation for Moleculer with service-provided ability definition and caching.
Note: This module is heavily under development.
Add this mixin to your auth service, to provide rules for other services.
import { createCASLAbilityProvider } from 'moleculer-casl'
const AuthService = {
mixins: [createCASLAbilityProvider(rulesFor)]
}
Add this mixin to any service that needs to use Abilities.
import { createCASLAbilityConsumer } from 'moleculer-casl'
const ProductService: Service & AbilityConsumerMethods = {
mixins: [createCASLAbilityConsumer()],
actions: {
create(ctx) {
const ability = await this.abilityFor(ctx.meta.user)
}
}
}
MIT License © 2023-PRESENT Nicholai Nissen