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

[Feature Request] A general-purposed context object for injecting values into access policy rules at runtime #1402

Open
ymc9 opened this issue May 3, 2024 · 0 comments

Comments

@ymc9
Copy link
Member

ymc9 commented May 3, 2024

Is your feature request related to a problem? Please describe.

Today, the only connection between the JS/TS world and ZModel is the auth() function; however, it's restricted to representing the current user. There are situations where you want to customize ZenStack's access policies at runtime by injecting values into the rules.

Describe the solution you'd like

We can have a new args() attribute function in ZModel, and a new args context object for the enhance TS-API. They'll be used in combination like:

const db = enhance(prisma, { user: currentUser, args: { quota: 1 } });
model Post {
  ...
  @@allow('create', args().quota > 0)
}

In an initial implementation, we can leave the args() function typed as Any to exempt it from type checking. After #783 is implemented, we can use the "type" feature to provide a proper typing.

Describe alternatives you've considered

Alternatively we can also try to add more fields into the user object and make them accessible through auth(). But I think it's a good idea to keep the concept of auth clean and dedicated to representing the user.

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

No branches or pull requests

1 participant