This section of the documentation is still work in progress and soon will be updated with more examples and details.
Please be patient while we work on the ongoing users and profiles refactoring as part of issue #376 .

The standard way to modify the default PocketBase behavior is through event hooks in your Go code.

Each event hook has 2 public methods:

  • Add(fn) - registers a new listener callback function to the specified event hook.
    Returning an error or hook.StopPropagation in the callback function stops the listeners execution chain.
  • Trigger(data) - triggers the event hook, aka. executes its listeners in the order they were added.
    This method usually is not called manually by users.

App hooks

OnBeforeServe

DB hooks

OnModelBeforeCreate
OnModelAfterCreate
OnModelBeforeUpdate
OnModelAfterUpdate
OnModelBeforeDelete
OnModelAfterDelete

Mailer hooks

OnMailerBeforeAdminResetPasswordSend
OnMailerAfterAdminResetPasswordSend
OnMailerBeforeUserResetPasswordSend
OnMailerAfterUserResetPasswordSend
OnMailerBeforeUserVerificationSend
OnMailerAfterUserVerificationSend
OnMailerBeforeUserChangeEmailSend
OnMailerAfterUserChangeEmailSend

Realtime API hooks

OnRealtimeConnectRequest
OnRealtimeBeforeSubscribeRequest
OnRealtimeAfterSubscribeRequest

Settings API hooks

OnSettingsListRequest
OnSettingsBeforeUpdateRequest
OnSettingsAfterUpdateRequest

File API hooks

OnFileDownloadRequest

Admin API hooks

OnAdminsListRequest
OnAdminViewRequest
OnAdminBeforeCreateRequest
OnAdminAfterCreateRequest
OnAdminBeforeUpdateRequest
OnAdminAfterUpdateRequest
OnAdminBeforeDeleteRequest
OnAdminAfterDeleteRequest
OnAdminAuthRequest

User API hooks

OnUsersListRequest
OnUserViewRequest
OnUserBeforeCreateRequest
OnUserAfterCreateRequest
OnUserBeforeUpdateRequest
OnUserAfterUpdateRequest
OnUserBeforeDeleteRequest
OnUserAfterDeleteRequest
OnUserAuthRequest
OnUserListExternalAuths
OnUserBeforeUnlinkExternalAuthRequest
OnUserAfterUnlinkExternalAuthRequest

Record API hooks

OnRecordsListRequest
OnRecordViewRequest
OnRecordBeforeCreateRequest
OnRecordAfterCreateRequest
OnRecordBeforeUpdateRequest
OnRecordAfterUpdateRequest
OnRecordBeforeDeleteRequest
OnRecordAfterDeleteRequest

Collection API hooks

OnCollectionsListRequest
OnCollectionViewRequest
OnCollectionBeforeCreateRequest
OnCollectionAfterCreateRequest
OnCollectionBeforeUpdateRequest
OnCollectionAfterUpdateRequest
OnCollectionBeforeDeleteRequest
OnCollectionAfterDeleteRequest
OnCollectionsBeforeImportRequest
OnCollectionsAfterImportRequest