Auth context helpers
Returns current authenticated user ID
Maps to auth.uid() in PostgreSQL (commonly used with Supabase).
This returns the user ID from the JWT token.
A ContextValue representing the current user's ID
// Basic user ownership
column('user_id').eq(auth.uid())
// In a policy
policy('user_documents')
.on('documents')
.read()
.when(column('user_id').eq(auth.uid()));
// With complex conditions
policy('project_access')
.on('projects')
.read()
.when(
column('created_by').eq(auth.uid())
.or(column('is_public').eq(true))
);
Session variable helpers
Get a session variable with type casting
Maps to current_setting(key)::TYPE in PostgreSQL.
Session variable key (e.g., 'app.current_tenant_id')
Type to cast to ('integer', 'uuid', 'boolean', 'timestamp', or 'text')
A ContextValue representing the session variable
// Integer session variable
column('tenant_id').eq(session.get('app.tenant_id', 'integer'))
// UUID session variable
column('org_id').eq(session.get('app.org_id', 'uuid'))
// Boolean session variable
column('is_admin').eq(session.get('app.is_admin', 'boolean'))
// Text session variable (default)
column('role').eq(session.get('app.role', 'text'))
Create a policy with typed table names
Create a typed column reference
Typed Rowguard instance with schema-aware API