core: Events
import core "ganigeorgiev.com/pocketbase/pocketbase/core"
Part of core.
Types
BackupEvent
type BackupEvent struct {
hook.Event
App App
Name string // the name of the backup to create/restore.
Exclude []string // list of dir entries to exclude from the backup create/restore.
}
BatchRequestEvent
type BatchRequestEvent struct {
hook.Event
*RequestEvent
Batch []*InternalRequest
}
BootstrapEvent
type BootstrapEvent struct {
hook.Event
App App
}
CollectionErrorEvent
type CollectionErrorEvent struct {
Error error
CollectionEvent
}
CollectionErrorEvent.Tags
func (e *CollectionErrorEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
CollectionEvent
type CollectionEvent struct {
hook.Event
App App
// Could be any of the ModelEventType* constants, like:
// - create
// - update
// - delete
// - validate
Type string
// contains filtered or unexported fields
}
CollectionEvent.Tags
func (e *CollectionEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
CollectionRequestEvent
type CollectionRequestEvent struct {
hook.Event
*RequestEvent
// contains filtered or unexported fields
}
CollectionRequestEvent.Tags
func (e *CollectionRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
CollectionsImportRequestEvent
type CollectionsImportRequestEvent struct {
hook.Event
*RequestEvent
CollectionsData []map[string]any
DeleteMissing bool
}
CollectionsListRequestEvent
type CollectionsListRequestEvent struct {
hook.Event
*RequestEvent
Collections []*Collection
Result *search.Result
}
FileDownloadRequestEvent
type FileDownloadRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
FileField *FileField
ServedPath string
ServedName string
// ThumbError indicates the a thumb wasn't able to be generated
// (e.g. because it didn't satisfy the support image formats or it timed out).
//
// Note that PocketBase fallbacks to the original file in case of a thumb error,
// but developers can check the field and provide their own custom thumb generation if necessary.
ThumbError error
// contains filtered or unexported fields
}
FileDownloadRequestEvent.Tags
func (e *FileDownloadRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
FileTokenRequestEvent
type FileTokenRequestEvent struct {
hook.Event
*RequestEvent
Token string
// contains filtered or unexported fields
}
FileTokenRequestEvent.Tags
func (e *FileTokenRequestEvent) Tags() []string
FilesystemCreateEvent
type FilesystemCreateEvent struct {
hook.Event
App App
// Kind is [FilesystemKindStorage], [FilesystemKindBackups] or a plugin's own kind.
Kind string
// Filesystem is the result. Left nil, the default one is created after the handlers.
Filesystem *filesystem.System
}
FilesystemCreateEvent is triggered by app.NewFilesystem() and app.NewBackupsFilesystem(); plugins may trigger it for their own kinds. A handler may set Filesystem (e.g. a default bucket when the app's own S3 is off); otherwise the default one from the app settings (S3 or local) is created.
FilesystemDeleteEvent
type FilesystemDeleteEvent struct {
hook.Event
*filesystem.DeleteEvent
App App
}
FilesystemNewWriterEvent
type FilesystemNewWriterEvent struct {
hook.Event
*filesystem.NewWriterEvent
App App
}
MailerEvent
type MailerEvent struct {
hook.Event
App App
Mailer mailer.Mailer
Message *mailer.Message
}
MailerRecordEvent
type MailerRecordEvent struct {
MailerEvent
Meta map[string]any
// contains filtered or unexported fields
}
MailerRecordEvent.Tags
func (e *MailerRecordEvent) Tags() []string
ModelErrorEvent
type ModelErrorEvent struct {
Error error
ModelEvent
}
ModelErrorEvent.Tags
func (e *ModelErrorEvent) Tags() []string
ModelEvent
type ModelEvent struct {
hook.Event
App App
// Could be any of the ModelEventType* constants, like:
// - create
// - update
// - delete
// - validate
Type string
// contains filtered or unexported fields
}
ModelEvent.Tags
func (e *ModelEvent) Tags() []string
RealtimeConnectRequestEvent
type RealtimeConnectRequestEvent struct {
hook.Event
*RequestEvent
Client subscriptions.Client
// IdleTimeout specifies the max duration to wait for a new message
// before closing the connection.
//
// Modifying the value after the connection has been established has no effect.
//
// Defaults to 5 minutes.
IdleTimeout time.Duration
// MaxTimeout specifies the maximum duration a realtime connection
// can remain open (including even if there are ongoing messages).
//
// Once the specified duration expires, the current connection will
// be terminated, until a client reconnect is issued (if the client is still active).
//
// Modifying the value after the connection has been established has no effect.
//
// Defaults to 30 minutes.
MaxTimeout time.Duration
}
RealtimeMessageEvent
type RealtimeMessageEvent struct {
hook.Event
*RequestEvent
Client subscriptions.Client
Message *subscriptions.Message
}
RealtimeSubscribeRequestEvent
type RealtimeSubscribeRequestEvent struct {
hook.Event
*RequestEvent
Client subscriptions.Client
Subscriptions []string
}
RecordAuthRefreshRequestEvent
type RecordAuthRefreshRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordAuthRefreshRequestEvent.Tags
func (e *RecordAuthRefreshRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordAuthRequestEvent
type RecordAuthRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
Token string
Meta any
AuthMethod string
// contains filtered or unexported fields
}
RecordAuthRequestEvent.Tags
func (e *RecordAuthRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordAuthWithOAuth2RequestEvent
type RecordAuthWithOAuth2RequestEvent struct {
hook.Event
*RequestEvent
ProviderName string
ProviderClient auth.Provider
Record *Record
OAuth2User *auth.AuthUser
CreateData map[string]any
IsNewRecord bool
// contains filtered or unexported fields
}
RecordAuthWithOAuth2RequestEvent.Tags
func (e *RecordAuthWithOAuth2RequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordAuthWithOTPRequestEvent
type RecordAuthWithOTPRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
OTP *OTP
// contains filtered or unexported fields
}
RecordAuthWithOTPRequestEvent.Tags
func (e *RecordAuthWithOTPRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordAuthWithPasswordRequestEvent
type RecordAuthWithPasswordRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
Identity string
IdentityField string
Password string
// contains filtered or unexported fields
}
RecordAuthWithPasswordRequestEvent.Tags
func (e *RecordAuthWithPasswordRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordConfirmEmailChangeRequestEvent
type RecordConfirmEmailChangeRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
NewEmail string
// contains filtered or unexported fields
}
RecordConfirmEmailChangeRequestEvent.Tags
func (e *RecordConfirmEmailChangeRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordConfirmPasswordResetRequestEvent
type RecordConfirmPasswordResetRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordConfirmPasswordResetRequestEvent.Tags
func (e *RecordConfirmPasswordResetRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordConfirmVerificationRequestEvent
type RecordConfirmVerificationRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordConfirmVerificationRequestEvent.Tags
func (e *RecordConfirmVerificationRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordCreateOTPRequestEvent
type RecordCreateOTPRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
Password string
// contains filtered or unexported fields
}
RecordCreateOTPRequestEvent.Tags
func (e *RecordCreateOTPRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordEnrichEvent
type RecordEnrichEvent struct {
hook.Event
App App
RequestInfo *RequestInfo
// contains filtered or unexported fields
}
RecordEnrichEvent.Tags
func (e *RecordEnrichEvent) Tags() []string
RecordErrorEvent
type RecordErrorEvent struct {
Error error
RecordEvent
}
RecordErrorEvent.Tags
func (e *RecordErrorEvent) Tags() []string
RecordEvent
type RecordEvent struct {
hook.Event
App App
// Could be any of the ModelEventType* constants, like:
// - create
// - update
// - delete
// - validate
Type string
// contains filtered or unexported fields
}
RecordEvent.Tags
func (e *RecordEvent) Tags() []string
RecordRequestEmailChangeRequestEvent
type RecordRequestEmailChangeRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
NewEmail string
// contains filtered or unexported fields
}
RecordRequestEmailChangeRequestEvent.Tags
func (e *RecordRequestEmailChangeRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordRequestEvent
type RecordRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordRequestEvent.Tags
func (e *RecordRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordRequestPasswordResetRequestEvent
type RecordRequestPasswordResetRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordRequestPasswordResetRequestEvent.Tags
func (e *RecordRequestPasswordResetRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordRequestVerificationRequestEvent
type RecordRequestVerificationRequestEvent struct {
hook.Event
*RequestEvent
Record *Record
// contains filtered or unexported fields
}
RecordRequestVerificationRequestEvent.Tags
func (e *RecordRequestVerificationRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RecordsListRequestEvent
type RecordsListRequestEvent struct {
hook.Event
*RequestEvent
// @todo consider removing and maybe add as generic to the search.Result?
Records []*Record
Result *search.Result
// contains filtered or unexported fields
}
RecordsListRequestEvent.Tags
func (e *RecordsListRequestEvent) Tags() []string
@todo consider storing the original collection name and use that as a tag to avoid the ambiguity when the collection is being modified (#7613); for new collection also maybe return empty tags?
RequestEvent
type RequestEvent struct {
App App
Auth *Record
router.Event
// contains filtered or unexported fields
}
RequestEvent defines the PocketBase router handler event.
RequestEvent.HasSuperuserAuth
func (e *RequestEvent) HasSuperuserAuth() bool
HasSuperuserAuth checks whether the current RequestEvent has superuser authentication loaded.
RequestEvent.RealIP
func (e *RequestEvent) RealIP() string
RealIP returns the "real" IP address from the configured trusted proxy headers.
If Settings.TrustedProxy is not configured or the found IP is empty, it fallbacks to e.RemoteIP().
NB! Be careful when used in a security critical context as it relies on the trusted proxy to be properly configured and your app to be accessible only through it. If you are not sure, use e.RemoteIP().
RequestEvent.RequestInfo
func (e *RequestEvent) RequestInfo() (*RequestInfo, error)
RequestInfo parses the current request into RequestInfo instance.
Note that the returned result is cached to avoid copying the request data multiple times but the auth state and other common store items are always refreshed in case they were changed by another handler.
ServeEvent
type ServeEvent struct {
hook.Event
App App
Router *router.Router[*RequestEvent]
Server *http.Server
CertManager *autocert.Manager
// Listener allow specifying a custom network listener.
//
// Leave it nil to use the default net.Listen("tcp", e.Server.Addr).
Listener net.Listener
// InstallerFunc is the "installer" function that is called after
// successful server tcp bind but only if there is no explicit
// superuser record created yet.
//
// It runs in a separate goroutine and its default value is [apis.DefaultInstallerFunc].
//
// It receives a system superuser record as argument that you can use to generate
// a short-lived auth token (e.g. systemSuperuser.NewStaticAuthToken(30 * time.Minute))
// and concatenate it as query param for your installer page
// (if you are using the client-side SDKs, you can then load the
// token with pb.authStore.save(token) and perform any Web API request
// e.g. creating a new superuser).
//
// Set it to nil if you want to skip the installer.
InstallerFunc func(app App, systemSuperuser *Record, baseURL string) error
// @todo experimental
//
// UIExtensions is a list with the superuser UI extensions.
UIExtensions []UIExtension
// StartBannerFunc defines a custom console startup banner.
//
// If not set, defaults to the system one that prints the
// current HTTP API and dashboard addresses.
//
// Assign StartBannerFunc to a function with an empty body if you
// want to disable the console print entirely.
StartBannerFunc func(baseURL string)
}
SettingsListRequestEvent
type SettingsListRequestEvent struct {
hook.Event
*RequestEvent
Settings *Settings
}
SettingsReloadEvent
type SettingsReloadEvent struct {
hook.Event
App App
}
SettingsUpdateRequestEvent
type SettingsUpdateRequestEvent struct {
hook.Event
*RequestEvent
OldSettings *Settings
NewSettings *Settings
}
TerminateEvent
type TerminateEvent struct {
hook.Event
App App
IsRestart bool
}
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.