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

All hooks have 3 main methods:

  • Bind(handler) adds a new handler to the specified event hook. A handler has 3 fields:
    • Id (optional) - the name of the handler (could be used as argument for Unbind)
    • Priority (optional) - the execution order of the handler (if empty fallbacks to the order of registration in the code).
    • Func (required) - the handler function.
  • BindFunc(func) is similar to Bind but registers a new handler from just the provided function.
    The registered handler is added with a default 0 priority and the id is autogenerated (the returned string value).
  • Trigger(event, oneOffHandlerFuncs...) triggers the event hook.
    This method rarely has to be called manually by users.

To remove an already registered hook handler, you can use the handler id and pass it to Unbind(id) or remove all handlers with UnbindAll() (!including system handlers).

All hook handler functions share the same func(e T) error signature and expect the user to call e.Next() if they want to proceed with the execution chain.

If you need to access the app instance from inside a hook handler prefer using the e.App field instead of reusing a parent scope app variable because the hook could be part of a transaction and can cause deadlock.

You can explore all available hooks below:

    These are lower level Record model hooks and could be triggered from anywhere (custom console command, scheduled cron job, when calling e.Save(record), etc.) and therefore they have no access to the request context!

    If you want to intercept the builtin Web APIs and to access their request body, query parameters, headers or the request auth state, then please use the designated Record *Request hooks .

    These are lower level Collection model hooks and could be triggered from anywhere (custom console command, scheduled cron job, when calling e.Save(collection), etc.) and therefore they have no access to the request context!

    If you want to intercept the builtin Web APIs and to access their request body, query parameters, headers or the request auth state, then please use the designated Collection *Request hooks .

    The request hooks are triggered only when the corresponding API request endpoint is accessed.

    The Model hooks are fired for all PocketBase structs that implements the Model DB interface - Record, Collection, Log, etc.

    For convenience, if you want to listen to only the Record or Collection DB model events without doing manual type assertion, you can use the OnRecord* and OnCollection* proxy hooks above.