Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Pass in permissions & authLevel as extensions options #24

Open
makinde opened this issue May 21, 2018 · 1 comment
Open

[RFC] Pass in permissions & authLevel as extensions options #24

makinde opened this issue May 21, 2018 · 1 comment

Comments

@makinde
Copy link
Contributor

makinde commented May 21, 2018

Right now we pass in the permissions object and getAuthLevel methods by assigning them directly into the schema object. If we add more options in the future, we'd probably add them in the same way. This means we're polluting that shared space with object keys, and these may potentially collide with other extensions/mongoose properties down the road.

mySchema.permissions = {...}
mySechma.getAuthLevel = functiion () {...}

A safer approach would be to have these options passed into the plugin installation:

mySchema.plugin(authz, {
  permissions: {...},
  getAuthLevel: function () {...},
});

This has a few advantages:

  1. All the configuration information for authorization is in one place, easy to see.
  2. It doesn't pollute a shared space, so we don't have to worry about conflicts of getting our information overwritten.

The challenge it presents are:

  1. We have to do a little more work to pass around this options object internally in the library. We could stick it in mySchema.authorizationOptions to have a sort of middle ground. And that key could be changed int he future since it's an internal implementation detail.
  2. The configuration object may look quite gnarly and seem harder to use.

Thoughts?

@brysgo
Copy link
Contributor

brysgo commented May 21, 2018

I like the idea, v2 is the place to put breaking changes so I think it is worth exploring.

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

No branches or pull requests

2 participants