Skip to main content
Event hooks allow you to execute custom logic at specific points in PocketBase’s lifecycle. You can use them to validate data, trigger side effects, send notifications, and more.

Hook types

PocketBase provides several categories of event hooks:
  • Application hooks: App lifecycle events (bootstrap, serve, terminate)
  • Model hooks: Generic model operations (create, update, delete, validate)
  • Record hooks: Record-specific operations
  • Collection hooks: Collection management events
  • Auth hooks: Authentication and authorization events
  • Request hooks: API request/response events
  • Mailer hooks: Email sending events
  • Settings hooks: Application settings events

Hook execution flow

Each hook follows this pattern: You can:
  • Prevent the default behavior by returning an error
  • Modify the event data before it’s processed
  • Execute side effects (logging, notifications, etc.)
  • Chain multiple handlers with priorities

Application hooks

OnBootstrap

Triggered when the application initializes.

OnServe

Triggered when the HTTP server is about to start. Use this to register custom routes.

OnTerminate

Triggered when the application is shutting down.

Model hooks

Model hooks work with any model type (records, collections, settings, etc.).

OnModelCreate

Triggered before a model is created.

OnModelUpdate

Triggered before a model is updated.

OnModelDelete

Triggered before a model is deleted.

Record hooks

Record hooks are specific to data records and support collection filtering.

OnRecordCreate

Triggered before a record is created.

OnRecordUpdate

Triggered before a record is updated.

OnRecordDelete

Triggered before a record is deleted.

After hooks

All record hooks also have “after” variants that run after the operation completes:
  • OnRecordAfterCreateSuccess / onRecordAfterCreateSuccess
  • OnRecordAfterUpdateSuccess / onRecordAfterUpdateSuccess
  • OnRecordAfterDeleteSuccess / onRecordAfterDeleteSuccess

Auth hooks

Hooks for authentication and authorization events.

OnRecordAuthRequest

Triggered on any successful authentication.

OnRecordAuthWithPasswordRequest

Triggered on password authentication.

OnRecordAuthWithOAuth2Request

Triggered on OAuth2 authentication.

Collection hooks

Hooks for collection management.

OnCollectionCreate

OnCollectionUpdate

Request hooks

Hooks for API requests.

OnRecordsListRequest

OnRecordViewRequest

Mailer hooks

OnMailerSend

Triggered before sending any email.

OnMailerRecordAuthAlertSend

Triggered when sending authentication alert emails.

Settings hooks

OnSettingsListRequest

OnSettingsUpdateRequest

Hook priorities

You can control the execution order of hooks using priorities:

Stopping execution

Return an error to prevent the operation from completing:

Next steps

Custom routes

Learn how to add custom API endpoints

JavaScript hooks

More JavaScript hook examples