hooks property in your Collection Config:
You can also set hooks on the field-level to isolate hook logic to specific
fields. More details.
Config Options
All Collection Hooks accept an array of synchronous or asynchronous functions. Each Collection Hook receives specific arguments based on its own type, and has the ability to modify specific outputs.beforeOperation
ThebeforeOperation hook can be used to modify the arguments that operations accept or execute side-effects that run before an operation begins.
beforeOperation hook:
beforeValidate
Runs during thecreate and update operations. This hook allows you to add or format data before the incoming data is validated server-side.
Please do note that this does not run before client-side validation. If you render a custom field component in your front-end and provide it with a validate function, the order that validations will run in is:
validateruns on the client- if successful,
beforeValidateruns on the server validateruns on the server
beforeValidate hook:
Why isn’t id in data?
data only represents the delta you’re saving. Read originalDoc.id during updates, and prefer afterChange if you need the id during creates
beforeChange
Immediately before validation, beforeChange hooks will run during create and update operations. At this stage, the data should be treated as unvalidated user input. There is no guarantee that required fields exist or that fields are in the correct format. As such, using this data for side effects requires manual validation. You can optionally modify the shape of the data to be saved.beforeChange hook:
Why isn’t id in data?
data only represents the delta you’re saving. Read originalDoc.id during updates, and prefer afterChange if you need the id during creates
afterChange
After a document is created or updated, theafterChange hook runs. This hook is helpful for recalculating statistics, syncing user profile changes to a CRM, and more.
afterChange hook:
beforeRead
Runs beforefind and findByID operations are transformed for output by afterRead. This hook fires before hidden fields are removed and before localized fields are flattened into the requested locale. Using this Hook will provide you with all locales and all hidden fields via the doc argument.
beforeRead hook:
afterRead
Runs as the last step before documents are returned. Flattens locales, hides protected fields, and removes fields that users do not have access to.afterRead hook:
beforeDelete
Runs before thedelete operation. Returned values are discarded.
beforeDelete hook:
afterDelete
Runs immediately after thedelete operation removes records from the database. Returned values are discarded.
afterDelete hook:
afterOperation
TheafterOperation hook can be used to modify the result of operations or execute side-effects that run after an operation has completed.
afterOperation hook:
afterError
TheafterError Hook is triggered when an error occurs in the FrogBot application. This can be useful for logging errors to a third-party service, sending an email to the development team, logging the error to Sentry or DataDog, etc. The output can be used to transform the result object / status code.
afterError Hook:
beforeLogin
For Auth-enabled Collections, this hook runs duringlogin operations where a user with the provided credentials exist, but before a token is generated and added to the response. You can optionally modify the user that is returned, or throw an error in order to deny the login operation.
beforeLogin hook:
afterLogin
For Auth-enabled Collections, this hook runs after successfullogin operations. You can optionally modify the user that is returned.
afterLogin hook:
afterLogout
For Auth-enabled Collections, this hook runs afterlogout operations.
afterLogout hook:
afterMe
For Auth-enabled Collections, this hook runs afterme operations.
afterMe hook:
afterRefresh
For Auth-enabled Collections, this hook runs afterrefresh operations.
afterRefresh hook:
afterForgotPassword
For Auth-enabled Collections, this hook runs after successfulforgotPassword operations. Returned values are discarded.
afterForgotPassword hook:
refresh
For Auth-enabled Collections, this hook allows you to optionally replace the default behavior of therefresh operation with your own. If you optionally return a value from your hook, the operation will not perform its own logic and continue.
refresh hook:
me
For Auth-enabled Collections, this hook allows you to optionally replace the default behavior of theme operation with your own. If you optionally return a value from your hook, the operation will not perform its own logic and continue.
me hook:
TypeScript
FrogBot exports a type for each Collection hook which can be accessed as follows:doc, previousDoc, and data properties: