stalniy / casl

CASL is an isomorphic authorization JavaScript library which restricts what resources a given user is allowed to access
https://casl.js.org/
MIT License
5.74k stars 257 forks source link

Unable to import `reactiveAbility` from casl/vue #890

Closed Waqar-SE closed 1 month ago

Waqar-SE commented 3 months ago

Describe the bug Unable to import reactiveAbility

To Reproduce Steps to reproduce the behavior: Try to import reactiveAbility and it will fail as index.js doesn't provide it.

Expected behavior Successful import of reactiveAbility

CASL Version @casl/vue - v

Environment:

Node 20, Vue 3

stalniy commented 3 months ago

I has never been a part of public interface. Could you please explain why do you need it?

Waqar-SE commented 3 months ago

For me the usecase is providing abilities to render function when testing the components.

stalniy commented 3 months ago

in this case it's an improvement not a bug. Why cannot you use plugin or provide/inject in tests?

Waqar-SE commented 3 months ago

To be able to provide the ability I need to build it, that's where the reactive ability is needed, to build the ability.

stalniy commented 3 months ago

You don’t need it because it’s hidden inside provideAbility and abilitiesPlugin

build ability in any way you like, casl/vue will make it reactive when you provide it. See the code:

https://github.com/stalniy/casl/blob/master/packages/casl-vue/src/useAbility.ts#L17

stalniy commented 1 month ago

Close as stale. Feel free to provide more details

Waqar-SE commented 2 weeks ago

Sorry, couldn't reply back.

The hook doesn't work when testing as the options in render(component,options) are supposed to be object not a hook. The object must contain the value which is returned reactiveAbility for key ABILITY_TOKEN that will be used when mounting the component for testing.