Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Receiving Error: Cannot find module './adapters/role-acl when attempting to add authorize to one of my models #241

Closed
harvey-magana opened this issue Jan 30, 2022 · 5 comments

Comments

@harvey-magana
Copy link

I hope this message finds you well. In trying to implement "const authorize = require('objection-authorize')(acl, library[, opts])" from the Usage section of your repository, I am stalled due to a missing dependency in the objection-authorize directory. It looks like node is trying to find it and it appears to be missing.
Screen Shot 2022-01-29 at 10 27 43 PM
Screen Shot 2022-01-29 at 10 29 01 PM
I'm very much liking the project and hope this can be resolved. In my project, I added the file directly from the role-acl repository but only to see if the issue would be fixed in any way. Thank you for your time.

@JaneJeon
Copy link
Owner

It looks like you're trying to use role-acl. As outlined in here: https://github.com/JaneJeon/objection-authorize#installation, for now I only support casl (because that's what I use), which is why it's saying it can't load the role-acl adapter - because, well, it doesn't exist!

I did used to support role-acl (I think back in v3? don't use that version please, there's been numerous improvements that have been made since); however, with the project being abandoned I dropped support for it as well, so if you want to continue using role-acl, there's nothing stopping you from implementing the adapter (everything else is already done) specifically for role-acl.

In particular, you should write an adapter that override these methods: https://github.com/JaneJeon/objection-authorize/blob/master/src/adapters/base.js#L97, and you can see an example of such implementation here: https://github.com/JaneJeon/objection-authorize/blob/master/src/adapters/casl.js.

The "base" adapter already has all of the context necessary for the ACL library (in your case, role-acl) to make the decision to reject things or not. All that is left is for you to basically wrap it in a way that role-acl understands.

@harvey-magana
Copy link
Author

Thank you, @JaneJeon . I wasn't trying to use role-acl but I will keep your feedback in mind from this point. Thank you also for getting back to me quick.

@JaneJeon
Copy link
Owner

Oh my god, I just realized what is going on now. You initialized the plugin WITHOUT specifying the library (in this case, it should be casl), and it defaulted to role-acl - a relic from the past.

I'll fix this and release a new version ASAP

@JaneJeon
Copy link
Owner

Okay, I addressed it in https://github.com/JaneJeon/objection-authorize/releases/tag/v5.0.2. Try pulling the latest version :)

@harvey-magana
Copy link
Author

Awesome, @JaneJeon ! Thank you for digging into it and finding the root cause of the issue there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants