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.- Go
- JavaScript
OnServe
Triggered when the HTTP server is about to start. Use this to register custom routes.- Go
- JavaScript
OnTerminate
Triggered when the application is shutting down.- Go
- JavaScript
Model hooks
Model hooks work with any model type (records, collections, settings, etc.).OnModelCreate
Triggered before a model is created.- Go
- JavaScript
OnModelUpdate
Triggered before a model is updated.- Go
- JavaScript
OnModelDelete
Triggered before a model is deleted.- Go
- JavaScript
Record hooks
Record hooks are specific to data records and support collection filtering.OnRecordCreate
Triggered before a record is created.- Go
- JavaScript
OnRecordUpdate
Triggered before a record is updated.- Go
- JavaScript
OnRecordDelete
Triggered before a record is deleted.- Go
- JavaScript
After hooks
All record hooks also have “after” variants that run after the operation completes:OnRecordAfterCreateSuccess/onRecordAfterCreateSuccessOnRecordAfterUpdateSuccess/onRecordAfterUpdateSuccessOnRecordAfterDeleteSuccess/onRecordAfterDeleteSuccess
- Go
- JavaScript
Auth hooks
Hooks for authentication and authorization events.OnRecordAuthRequest
Triggered on any successful authentication.- Go
- JavaScript
OnRecordAuthWithPasswordRequest
Triggered on password authentication.- Go
- JavaScript
OnRecordAuthWithOAuth2Request
Triggered on OAuth2 authentication.- Go
- JavaScript
Collection hooks
Hooks for collection management.OnCollectionCreate
- Go
- JavaScript
OnCollectionUpdate
- Go
- JavaScript
Request hooks
Hooks for API requests.OnRecordsListRequest
- Go
- JavaScript
OnRecordViewRequest
- Go
- JavaScript
Mailer hooks
OnMailerSend
Triggered before sending any email.- Go
- JavaScript
OnMailerRecordAuthAlertSend
Triggered when sending authentication alert emails.- Go
- JavaScript
Settings hooks
OnSettingsListRequest
- Go
- JavaScript
OnSettingsUpdateRequest
- Go
- JavaScript
Hook priorities
You can control the execution order of hooks using priorities:- Go
- JavaScript
Stopping execution
Return an error to prevent the operation from completing:- Go
- JavaScript
Next steps
Custom routes
Learn how to add custom API endpoints
JavaScript hooks
More JavaScript hook examples