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 db instead of using baseDB directly
  • Pattern: Server actions call utilities and need to pass their authenticated db client

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:

Installs
2
GitHub Stars
1
First Seen
Mar 4, 2026
zenstack-authenticated-db-params — hankanman/claude-config