docs: update collection hooks

This commit is contained in:
Dan Ribbens
2022-07-09 19:57:58 -04:00
parent 166bd31506
commit 8d550d411e
2 changed files with 32 additions and 5 deletions

View File

@@ -22,6 +22,8 @@ Additionally, `auth`-enabled collections feature the following hooks:
- [beforeLogin](#beforelogin) - [beforeLogin](#beforelogin)
- [afterLogin](#afterlogin) - [afterLogin](#afterlogin)
- [afterLogout](#afterlogout) - [afterLogout](#afterlogout)
- [afterRefresh](#afterrefresh)
- [afterMe](#afterme)
- [afterForgotPassword](#afterforgotpassword) - [afterForgotPassword](#afterforgotpassword)
## Config ## Config
@@ -50,6 +52,8 @@ module.exports = {
beforeLogin: [(args) => {...}], beforeLogin: [(args) => {...}],
afterLogin: [(args) => {...}], afterLogin: [(args) => {...}],
afterLogout: [(args) => {...}], afterLogout: [(args) => {...}],
afterRefresh: [(args) => {...}],
afterMe: [(args) => {...}],
afterForgotPassword: [(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. 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 ```js
const beforeOperationHook = async ({ const beforeOperationHook = async ({
@@ -192,14 +196,37 @@ const afterLoginHook = async ({
### afterLogout ### afterLogout
For auth-enabled Collections, this hook runs after before `logout` operations. For auth-enabled Collections, this hook runs after `logout` operations.
```js ```js
const afterLoginHook = async ({ const afterLogoutHook = async ({
req, // full express request 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 ### afterForgotPassword
For auth-enabled Collections, this hook runs after successful `forgotPassword` operations. Returned values are discarded. For auth-enabled Collections, this hook runs after successful `forgotPassword` operations. Returned values are discarded.
@@ -231,6 +258,8 @@ import type {
CollectionBeforeLoginHook, CollectionBeforeLoginHook,
CollectionAfterLoginHook, CollectionAfterLoginHook,
CollectionAfterLogoutHook, CollectionAfterLogoutHook,
CollectionAfterRefreshHook,
CollectionAfterMeHook,
CollectionAfterForgotPasswordHook, CollectionAfterForgotPasswordHook,
} from 'payload/types'; } from 'payload/types';

View File

@@ -34,8 +34,6 @@ export type HookOperationType =
| 'delete' | 'delete'
| 'refresh' | 'refresh'
| 'login' | 'login'
| 'logout'
| 'me'
| 'forgotPassword'; | 'forgotPassword';
type CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>; type CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>;