Skip to main content
PocketBase provides numerous event hooks that allow you to execute custom logic at specific points in the application lifecycle.

Hook types

Hooks are categorized by when they fire in the lifecycle:
  • Before hooks - Fire before an operation (can prevent the operation)
  • After hooks - Fire after a successful operation
  • Error hooks - Fire when an operation fails

Record hooks

Record lifecycle

Filtering by collection

You can filter hooks to specific collections using tags:

Record create hooks

Record update hooks

Record delete hooks

Record validation hooks

API request hooks

Record request hooks

Authentication hooks

Email hooks

Collection hooks

Application hooks

Serve hook

Settings hooks

Batch hooks

File hooks

Realtime hooks

Hook execution order

For a record create operation, hooks fire in this order:
  1. onRecordCreateRequest - API request starts
  2. onRecordValidate - Validation runs
  3. onRecordCreate - Before database operation
  4. onRecordCreateExecute - During database transaction
  5. onRecordAfterCreateSuccess - After successful creation
If any hook throws an error:
  • Later hooks in the chain won’t execute
  • onRecordAfterCreateError will fire instead of success hooks
  • Database changes are rolled back

Best practices

Keep hooks focused

Handle errors gracefully

Use collection tags