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

Add auth() attribute to fields level #375

Closed Azzerty23 closed 1 year ago

Azzerty23 commented 1 year ago

Is your feature request related to a problem? Please describe. I love abstract models!! I tend to overuse them to track the origin of write operations. I would like to automatically retrieve the currentUser at the createdBy field level in particular.

Describe the solution you'd like

abstract model Base {
    id          String   @id @default(cuid())
    createdAt   DateTime @default(now())
    updatedAt   DateTime @updatedAt
    deletedAt   DateTime?
    createdBy   String   @default(auth().id)  <---- here
    updatedBy   String?
    deletedBy   String?
}

Describe alternatives you've considered To keep it simple, I have to pass the currentUser.id in my forms.

Capture d’écran 2023-05-02 à 20 20 26
Azzerty23 commented 1 year ago

I'm closing it as it has already been discussed: https://github.com/zenstackhq/zenstack/issues/310