zenstack-authenticated-db-params
Installation
SKILL.md
ZenStack Authenticated DB Parameter Pattern
Problem
When creating utility functions that need to accept an authenticated ZenStack database client
(to enforce access control policies), TypeScript throws circular reference errors if you
try to use ReturnType<typeof db.$setAuth> directly in the function signature.
Context / Trigger Conditions
- TypeScript Error:
TS2502: 'db' is referenced directly or indirectly in its own type annotation - Project Stack: ZenStack ORM (built on Prisma) + Better Auth
- Scenario: Refactoring utilities to accept authenticated
dbinstead of usingbaseDBdirectly - Pattern: Server actions call utilities and need to pass their authenticated
dbclient
Solution
Step 1: Import db Client and Create Type Alias
Instead of importing EnhancedPrismaClient (which doesn't exist), import the base db client
and create a local type alias: