PocketBase API Rules

Configure PocketBase collection access rules and filter expressions for record-level permissions.

30.5k|3.5k|Updated Jul 4, 2025
One-click install
npx skills add https://github.com/davila7/claude-code-templates --skill pocketbase-api-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PocketBase API Rules
Source: https://github.com/davila7/claude-code-templates/tree/main/cli-tool/components/skills/pocketbase/pb-api-rules
Command: npx skills add https://github.com/davila7/claude-code-templates --skill pocketbase-api-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Setting correct access control in PocketBase requires mastering five rule types, a custom filter expression syntax, and request macros, and misconfigured rules cause confusing 403/404 errors or accidental data exposure.

Core Features & Use Cases

  • Rule Type Reference: Explains all 5 collection rules (List, View, Create, Update, Delete) including the critical difference between locked (superuser-only) and empty-string (public) values.
  • Filter Expression Syntax: Covers all operators including the ?= family for multi-valued fields, logical operators, datetime macros, and geoDistance queries.
  • Request & Collection Macros: Documents @request.auth.*, @request.body.*, and cross-collection @collection.* lookups, plus field modifiers like :isset, :changed, and :length.
  • Use Case: When building a team-based app, use the documented membership pattern @collection.memberships.user ?= @request.auth.id to restrict record access to team members only.

Quick Start

Ask the AI to write PocketBase API rules so that only a record's author can update or delete it while everyone can read it.

Frequently Asked Questions about PocketBase API Rules

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write PocketBase API rules for owner-only access?

Set the View, Update, and Delete rules to `author = @request.auth.id` so only the record's author can perform those actions. Leave List and View as an empty string if records should be publicly readable.

What is the difference between locked and empty string in PocketBase rules?

A locked (null) rule means only superusers can perform the action, while an empty string means everyone including guests can. This distinction is critical because an empty string unintentionally exposes data publicly.

Why does my PocketBase rule fail on multi-select or relation fields?

Using `=` on multi-valued fields compares the raw JSON string instead of individual values. Use the `?=` operator (any/has) for multi-select, multi-relation, and multi-file fields to check individual elements.

How do I check team membership across collections in PocketBase rules?

Use the `@collection.*` macro, for example `@collection.memberships.user ?= @request.auth.id && @collection.memberships.team ?= team`. This performs an implicit EXISTS subquery, so add indexes on large datasets for performance.

Can PocketBase rules prevent users from changing specific fields?

Yes, use field modifiers in update rules. For example, `owner:changed = false` blocks modification of the owner field, and `@request.body.role:isset = false` prevents the role field from being sent at all.

Why do superusers bypass PocketBase API rules?

Superusers always bypass API rules by design, so rules only apply to regular auth records and guests. Test permission logic with a regular user account rather than a superuser token to see actual rule behavior.