docs: update collection hooks
This commit is contained in:
@@ -22,6 +22,8 @@ Additionally, `auth`-enabled collections feature the following hooks:
|
||||
- [beforeLogin](#beforelogin)
|
||||
- [afterLogin](#afterlogin)
|
||||
- [afterLogout](#afterlogout)
|
||||
- [afterRefresh](#afterrefresh)
|
||||
- [afterMe](#afterme)
|
||||
- [afterForgotPassword](#afterforgotpassword)
|
||||
|
||||
## Config
|
||||
@@ -50,6 +52,8 @@ module.exports = {
|
||||
beforeLogin: [(args) => {...}],
|
||||
afterLogin: [(args) => {...}],
|
||||
afterLogout: [(args) => {...}],
|
||||
afterRefresh: [(args) => {...}],
|
||||
afterMe: [(args) => {...}],
|
||||
afterForgotPassword: [(args) => {...}],
|
||||
}
|
||||
}
|
||||
@@ -59,7 +63,7 @@ module.exports = {
|
||||
|
||||
The `beforeOperation` Hook type can be used to modify the arguments that operations accept or execute side-effects that run before an operation begins.
|
||||
|
||||
Available Collection operations include `create`, `read`, `update`, `delete`, `refresh`, and `forgotPassword`.
|
||||
Available Collection operations include `create`, `read`, `update`, `delete`, `login`, `refresh` and `forgotPassword`.
|
||||
|
||||
```js
|
||||
const beforeOperationHook = async ({
|
||||
@@ -192,14 +196,37 @@ const afterLoginHook = async ({
|
||||
|
||||
### afterLogout
|
||||
|
||||
For auth-enabled Collections, this hook runs after before `logout` operations.
|
||||
For auth-enabled Collections, this hook runs after `logout` operations.
|
||||
|
||||
```js
|
||||
const afterLoginHook = async ({
|
||||
const afterLogoutHook = async ({
|
||||
req, // full express request
|
||||
}) => {...}
|
||||
```
|
||||
|
||||
### afterRefresh
|
||||
|
||||
For auth-enabled Collections, this hook runs after `refresh` operations.
|
||||
|
||||
```js
|
||||
const afterRefreshHook = async ({
|
||||
req, // full express request
|
||||
res, // full express response
|
||||
token, // newly refreshed user token
|
||||
}) => {...}
|
||||
```
|
||||
|
||||
### afterMe
|
||||
|
||||
For auth-enabled Collections, this hook runs after `me` operations.
|
||||
|
||||
```js
|
||||
const afterMeHook = async ({
|
||||
req, // full express request
|
||||
response, // response to return
|
||||
}) => {...}
|
||||
```
|
||||
|
||||
### afterForgotPassword
|
||||
|
||||
For auth-enabled Collections, this hook runs after successful `forgotPassword` operations. Returned values are discarded.
|
||||
@@ -231,6 +258,8 @@ import type {
|
||||
CollectionBeforeLoginHook,
|
||||
CollectionAfterLoginHook,
|
||||
CollectionAfterLogoutHook,
|
||||
CollectionAfterRefreshHook,
|
||||
CollectionAfterMeHook,
|
||||
CollectionAfterForgotPasswordHook,
|
||||
} from 'payload/types';
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ export type HookOperationType =
|
||||
| 'delete'
|
||||
| 'refresh'
|
||||
| 'login'
|
||||
| 'logout'
|
||||
| 'me'
|
||||
| 'forgotPassword';
|
||||
|
||||
type CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>;
|
||||
|
||||
Reference in New Issue
Block a user