You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hooks/collections.mdx
+42-21Lines changed: 42 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ Collections feature the ability to define the following hooks:
16
16
-[afterRead](#afterread)
17
17
-[beforeDelete](#beforedelete)
18
18
-[afterDelete](#afterdelete)
19
+
-[afterOperation](#afteroperation)
19
20
20
21
Additionally, `auth`-enabled collections feature the following hooks:
21
22
@@ -31,6 +32,7 @@ Additionally, `auth`-enabled collections feature the following hooks:
31
32
All collection Hook properties accept arrays of synchronous or asynchronous functions. Each Hook type receives specific arguments and has the ability to modify specific outputs.
returndata; // Return data to either create or update a document with
100
-
}
103
+
};
101
104
```
102
105
103
106
### beforeChange
104
107
105
108
Immediately following validation, `beforeChange` hooks will run within `create` and `update` operations. At this stage, you can be confident that the data that will be saved to the document is valid in accordance to your field validations. You can optionally modify the shape of data to be saved.
returndata; // Return data to either create or update a document with
117
-
}
120
+
};
118
121
```
119
122
120
123
### afterChange
121
124
122
125
After a document is created or updated, the `afterChange` hook runs. This hook is helpful to recalculate statistics such as total sales within a global, syncing user profile changes to a CRM, and more.
operation, // name of the operation ie. 'create', 'update'
132
135
}) => {
133
136
returndoc;
134
-
}
137
+
};
135
138
```
136
139
137
140
### beforeRead
138
141
139
142
Runs before `find` 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.
The `afterOperation` hook can be used to modify the result of operations or execute side-effects that run after an operation has completed.
203
+
204
+
Available Collection operations include `create`, `find`, `findByID`, `update`, `updateByID`, `delete`, `deleteByID`, `login`, `refresh`, and `forgotPassword`.
result, // the result of the operation, before modifications
213
+
}) => {
214
+
returnresult; // return modified result as necessary
215
+
};
216
+
```
217
+
197
218
### beforeLogin
198
219
199
220
For auth-enabled Collections, this hook runs during `login` 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.
0 commit comments