Documentation Index
Fetch the complete documentation index at: https://docs.cocobase.cc/llms.txt
Use this file to discover all available pages before exploring further.
Hooks
Hooks let you attach cloud functions to lifecycle events in your project — document changes, user registration, login, and more. When the event fires, Cocobase calls your function automatically with the relevant data.Hooks are configured in the Cocobase Dashboard. Your cloud functions must already be deployed before you can attach them to a hook.
How Hooks Work
Every hook calls your cloud function via HTTP with a JSON payload containing the event data. Inside your function you access it throughreq.payload:
X-Hook-Event header with the event name string, useful if one function handles multiple events.
Two Types of Hooks
Collection Hooks
Attached to a specific collection. Fire when documents in that collection are created, updated, or deleted.| Event | When |
|---|---|
pre_save | Before a document is created or updated |
post_save | After a document is created or updated |
pre_delete | Before a document is deleted |
post_delete | After a document is deleted |
Auth Hooks
Attached to your project’s app-user system (not a specific collection). Fire during the authentication lifecycle.| Event | When | Can Block? |
|---|---|---|
pre_register | Before a new user is saved to the database | ✅ Yes |
post_register | After a new user is successfully registered | No |
pre_login | After password verified, before token is issued | ✅ Yes |
post_login | After a user logs in and receives a token | No |
pre_user_update | Before a user’s profile is updated | No |
post_user_update | After a user’s profile is updated | No |
pre_user_delete | Before a user is deleted | No |
post_user_delete | After a user is deleted | No |
Blocking vs Background Hooks
Background (fire-and-forget)
Most hooks run in the background — Cocobase fires the function and does not wait for a response. The main operation (save, delete, login) completes immediately. Errors in your function are logged but never affect the user.Blocking (pre_login, pre_register)
pre_login and pre_register run synchronously and can cancel the operation. If your function returns {"block": true, "reason": "..."}, Cocobase rejects the request with a 403 and sends reason back to the caller.
Setting Up Hooks
Collection Hooks
- Go to Dashboard → Your Project → Collections
- Click the collection you want to attach a hook to
- Open the Settings tab
- Click Add Hook
- Choose an event and select your cloud function
- Save
Auth Hooks
- Go to Dashboard → Your Project → App Users
- Click the Auth Hooks tab
- Click Add Hook
- Choose an event and select your cloud function
- Save
Next Steps
- Collection Hooks — Full reference for
pre_save,post_save,pre_delete,post_delete - Auth Hooks — Full reference for all auth lifecycle events
- Hook Examples — Copy-paste recipes for common use cases
