zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Using `this` causes policy generation error in field-level access policies #665

Closed ymc9 closed 1 year ago

ymc9 commented 1 year ago
model User {
  id Int @id @default(autoincrement())
  admin Boolean @default(false)
  username String @unique @allow("all", auth() == this) @allow("all", auth().admin)
  password String @password @default("") @allow("all", auth() == this) @allow("all", auth().admin)
  firstName String @default("")
  lastName String @default("")

  @@allow('all', auth() == this)
  @@allow('all', auth().admin)
  @@allow('create', true)
}

Output:

node_modules/.zenstack/policy.ts:58:22 - error TS2304: Cannot find name 'id'.
58     return ((user == id) || (user?.admin ?? null))
ymc9 commented 1 year ago

Fixed in 1.0.0-beta.21