payload 1.0.27 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -4
- package/dist/admin/components/elements/Status/index.js +1 -1
- package/dist/admin/components/elements/ViewDescription/types.d.ts +1 -1
- package/dist/admin/components/elements/WhereBuilder/index.js +3 -1
- package/dist/admin/components/forms/field-types/Array/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Array/index.js +201 -6
- package/dist/admin/components/forms/field-types/Blocks/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Blocks/index.js +213 -6
- package/dist/admin/components/forms/field-types/Collapsible/index.js +2 -2
- package/dist/admin/components/forms/field-types/Row/index.js +2 -2
- package/dist/admin/components/forms/field-types/Tabs/index.js +2 -2
- package/dist/admin/components/forms/field-types/getFieldPath.d.ts +2 -0
- package/dist/admin/components/forms/field-types/getFieldPath.js +6 -0
- package/dist/admin/components/forms/field-types/index.d.ts +23 -23
- package/dist/admin/components/utilities/RenderCustomComponent/types.d.ts +2 -2
- package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +1 -1
- package/dist/auth/operations/local/forgotPassword.js +3 -6
- package/dist/auth/operations/local/login.js +6 -9
- package/dist/auth/operations/local/resetPassword.js +4 -7
- package/dist/auth/operations/local/unlock.js +4 -7
- package/dist/collections/buildSchema.js +2 -1
- package/dist/collections/config/types.d.ts +2 -2
- package/dist/collections/dataloader.js +16 -8
- package/dist/collections/operations/local/create.d.ts +2 -2
- package/dist/collections/operations/local/create.js +11 -13
- package/dist/collections/operations/local/find.js +6 -10
- package/dist/collections/operations/local/findByID.js +6 -10
- package/dist/collections/operations/local/findVersionByID.js +6 -9
- package/dist/config/types.d.ts +13 -13
- package/dist/fields/config/sanitize.js +3 -3
- package/dist/fields/config/schema.js +3 -3
- package/dist/fields/config/types.d.ts +9 -9
- package/dist/fields/validations.js +43 -1
- package/dist/globals/config/types.d.ts +1 -1
- package/dist/mongoose/buildSchema.d.ts +1 -0
- package/dist/mongoose/buildSchema.js +3 -3
- package/dist/utilities/getIDType.d.ts +2 -0
- package/dist/utilities/getIDType.js +11 -0
- package/dist/utilities/isValidID.d.ts +1 -0
- package/dist/utilities/isValidID.js +16 -0
- package/docs/access-control/collections.mdx +21 -12
- package/docs/access-control/fields.mdx +5 -3
- package/docs/access-control/globals.mdx +8 -4
- package/docs/access-control/overview.mdx +1 -1
- package/docs/admin/components.mdx +29 -25
- package/docs/admin/customizing-css.mdx +2 -2
- package/docs/admin/overview.mdx +2 -2
- package/docs/admin/webpack.mdx +8 -7
- package/docs/authentication/config.mdx +14 -9
- package/docs/authentication/operations.mdx +22 -22
- package/docs/authentication/overview.mdx +8 -6
- package/docs/authentication/using-middleware.mdx +1 -1
- package/docs/configuration/collections.mdx +11 -7
- package/docs/configuration/globals.mdx +9 -5
- package/docs/configuration/localization.mdx +33 -31
- package/docs/configuration/overview.mdx +4 -7
- package/docs/email/overview.mdx +11 -7
- package/docs/fields/array.mdx +6 -5
- package/docs/fields/blocks.mdx +6 -4
- package/docs/fields/checkbox.mdx +6 -5
- package/docs/fields/code.mdx +6 -5
- package/docs/fields/collapsible.mdx +6 -5
- package/docs/fields/date.mdx +6 -5
- package/docs/fields/email.mdx +6 -5
- package/docs/fields/group.mdx +6 -5
- package/docs/fields/number.mdx +6 -5
- package/docs/fields/overview.mdx +40 -38
- package/docs/fields/point.mdx +6 -4
- package/docs/fields/radio.mdx +5 -3
- package/docs/fields/relationship.mdx +21 -21
- package/docs/fields/rich-text.mdx +9 -7
- package/docs/fields/row.mdx +5 -3
- package/docs/fields/select.mdx +4 -3
- package/docs/fields/tabs.mdx +5 -3
- package/docs/fields/text.mdx +5 -3
- package/docs/fields/textarea.mdx +5 -3
- package/docs/fields/ui.mdx +5 -3
- package/docs/fields/upload.mdx +5 -3
- package/docs/getting-started/concepts.mdx +1 -1
- package/docs/graphql/extending.mdx +1 -1
- package/docs/graphql/overview.mdx +8 -4
- package/docs/hooks/collections.mdx +62 -36
- package/docs/hooks/fields.mdx +5 -3
- package/docs/hooks/globals.mdx +25 -17
- package/docs/local-api/overview.mdx +27 -4
- package/docs/plugins/overview.mdx +3 -4
- package/docs/production/deployment.mdx +1 -1
- package/docs/queries/overview.mdx +4 -2
- package/docs/queries/pagination.mdx +1 -1
- package/docs/rest-api/overview.mdx +4 -2
- package/docs/upload/overview.mdx +35 -29
- package/docs/versions/autosave.mdx +4 -2
- package/docs/versions/drafts.mdx +8 -4
- package/docs/versions/overview.mdx +1 -1
- package/package.json +1 -1
- package/types.d.ts +21 -0
- package/dist/admin/components/forms/field-types/Array/Array.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Array/Array.js +0 -201
- package/dist/admin/components/forms/field-types/Blocks/Blocks.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +0 -213
|
@@ -38,9 +38,16 @@ You can override a set of admin panel-wide components by providing a component t
|
|
|
38
38
|
#### Full example:
|
|
39
39
|
|
|
40
40
|
`payload.config.js`
|
|
41
|
-
```
|
|
42
|
-
import { buildConfig } from 'payload/config'
|
|
43
|
-
import {
|
|
41
|
+
```ts
|
|
42
|
+
import { buildConfig } from 'payload/config'
|
|
43
|
+
import {
|
|
44
|
+
MyCustomNav,
|
|
45
|
+
MyCustomLogo,
|
|
46
|
+
MyCustomIcon,
|
|
47
|
+
MyCustomAccount,
|
|
48
|
+
MyCustomDashboard,
|
|
49
|
+
MyProvider,
|
|
50
|
+
} from './customComponents';
|
|
44
51
|
|
|
45
52
|
export default buildConfig({
|
|
46
53
|
admin: {
|
|
@@ -55,9 +62,9 @@ export default buildConfig({
|
|
|
55
62
|
Dashboard: MyCustomDashboard,
|
|
56
63
|
},
|
|
57
64
|
providers: [MyProvider],
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
61
68
|
```
|
|
62
69
|
|
|
63
70
|
*For more examples regarding how to customize components, look at the following [examples](https://github.com/payloadcms/payload/tree/master/test/admin/components).*
|
|
@@ -100,20 +107,17 @@ All Payload fields support the ability to swap in your own React components. So,
|
|
|
100
107
|
|
|
101
108
|
When swapping out the `Field` component, you'll be responsible for sending and receiving the field's `value` from the form itself. To do so, import the `useField` hook as follows:
|
|
102
109
|
|
|
103
|
-
```
|
|
104
|
-
import { useField } from 'payload/components/forms'
|
|
110
|
+
```tsx
|
|
111
|
+
import { useField } from 'payload/components/forms'
|
|
112
|
+
|
|
113
|
+
type Props = { path: string }
|
|
105
114
|
|
|
106
|
-
const CustomTextField = ({ path }) => {
|
|
115
|
+
const CustomTextField: React.FC<Props> = ({ path }) => {
|
|
107
116
|
// highlight-start
|
|
108
|
-
const { value, setValue } = useField({ path })
|
|
117
|
+
const { value, setValue } = useField<Props>({ path })
|
|
109
118
|
// highlight-end
|
|
110
119
|
|
|
111
|
-
return (
|
|
112
|
-
<input
|
|
113
|
-
onChange={(e) => setValue(e.target.value)}
|
|
114
|
-
value={value}
|
|
115
|
-
/>
|
|
116
|
-
)
|
|
120
|
+
return <input onChange={e => setValue(e.target.value)} value={value.path} />
|
|
117
121
|
}
|
|
118
122
|
```
|
|
119
123
|
|
|
@@ -121,10 +125,10 @@ const CustomTextField = ({ path }) => {
|
|
|
121
125
|
|
|
122
126
|
There are times when a custom field component needs to have access to data from other fields. This can be done using `getDataByPath` from `useWatchForm` as follows:
|
|
123
127
|
|
|
124
|
-
```
|
|
128
|
+
```tsx
|
|
125
129
|
import { useWatchForm } from 'payload/components/forms';
|
|
126
130
|
|
|
127
|
-
const DisplayFee = () => {
|
|
131
|
+
const DisplayFee: React.FC = () => {
|
|
128
132
|
const { getDataByPath } = useWatchForm();
|
|
129
133
|
|
|
130
134
|
const amount = getDataByPath('amount');
|
|
@@ -132,7 +136,7 @@ const DisplayFee = () => {
|
|
|
132
136
|
|
|
133
137
|
if (amount && feePercentage) {
|
|
134
138
|
return (
|
|
135
|
-
<span>The fee is ${
|
|
139
|
+
<span>The fee is ${(amount * feePercentage) / 100}</span>
|
|
136
140
|
);
|
|
137
141
|
}
|
|
138
142
|
};
|
|
@@ -142,10 +146,10 @@ const DisplayFee = () => {
|
|
|
142
146
|
|
|
143
147
|
The document ID can be very useful for certain custom components. You can get the `id` from the `useDocumentInfo` hook. Here is an example of a `UI` field using `id` to link to related collections:
|
|
144
148
|
|
|
145
|
-
```
|
|
149
|
+
```tsx
|
|
146
150
|
import { useDocumentInfo } from 'payload/components/utilities';
|
|
147
151
|
|
|
148
|
-
const LinkFromCategoryToPosts = () => {
|
|
152
|
+
const LinkFromCategoryToPosts: React.FC = () => {
|
|
149
153
|
// highlight-start
|
|
150
154
|
const { id } = useDocumentInfo();
|
|
151
155
|
// highlight-end
|
|
@@ -222,10 +226,10 @@ To make use of Payload SCSS variables / mixins to use directly in your own compo
|
|
|
222
226
|
|
|
223
227
|
In any custom component you can get the selected locale with the `useLocale` hook. Here is a simple example:
|
|
224
228
|
|
|
225
|
-
```
|
|
229
|
+
```tsx
|
|
226
230
|
import { useLocale } from 'payload/components/utilities';
|
|
227
231
|
|
|
228
|
-
const Greeting = () => {
|
|
232
|
+
const Greeting: React.FC = () => {
|
|
229
233
|
// highlight-start
|
|
230
234
|
const locale = useLocale();
|
|
231
235
|
// highlight-end
|
|
@@ -237,6 +241,6 @@ const Greeting = () => {
|
|
|
237
241
|
|
|
238
242
|
return (
|
|
239
243
|
<span> { trans[locale] } </span>
|
|
240
|
-
)
|
|
241
|
-
}
|
|
244
|
+
);
|
|
245
|
+
};
|
|
242
246
|
```
|
|
@@ -13,7 +13,7 @@ You can add your own CSS by providing your base Payload config with a path to yo
|
|
|
13
13
|
To do so, provide your base Payload config with a path to your own stylesheet. It can be either a CSS or SCSS file.
|
|
14
14
|
|
|
15
15
|
**Example in payload.config.js:**
|
|
16
|
-
```
|
|
16
|
+
```ts
|
|
17
17
|
import { buildConfig } from 'payload/config';
|
|
18
18
|
import path from 'path';
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ const config = buildConfig({
|
|
|
21
21
|
admin: {
|
|
22
22
|
css: path.resolve(__dirname, 'relative/path/to/stylesheet.scss'),
|
|
23
23
|
},
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
### Overriding built-in styles
|
package/docs/admin/overview.mdx
CHANGED
|
@@ -45,14 +45,14 @@ All options for the Admin panel are defined in your base Payload config file.
|
|
|
45
45
|
To specify which Collection to use to log in to the Admin panel, pass the `admin` options a `user` key equal to the slug of the Collection that you'd like to use.
|
|
46
46
|
|
|
47
47
|
`payload.config.js`:
|
|
48
|
-
```
|
|
48
|
+
```ts
|
|
49
49
|
import { buildConfig } from 'payload/config';
|
|
50
50
|
|
|
51
51
|
const config = buildConfig({
|
|
52
52
|
admin: {
|
|
53
53
|
user: 'admins', // highlight-line
|
|
54
54
|
},
|
|
55
|
-
})
|
|
55
|
+
});
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
By default, if you have not specified a Collection, Payload will automatically provide you with a `User` Collection which will be used to access the Admin panel. You can customize or override the fields and settings of the default `User` Collection by passing your own collection using `users` as its `slug` to Payload. When this is done, Payload will use your provided `User` Collection instead of its default version.
|
package/docs/admin/webpack.mdx
CHANGED
|
@@ -10,8 +10,8 @@ Payload uses Webpack 5 to build the Admin panel. It comes with support for many
|
|
|
10
10
|
|
|
11
11
|
To extend the Webpack config, add the `webpack` key to your base Payload config, and provide a function that accepts the default Webpack config as its only argument:
|
|
12
12
|
|
|
13
|
-
`payload.config.
|
|
14
|
-
```
|
|
13
|
+
`payload.config.ts`
|
|
14
|
+
```ts
|
|
15
15
|
import { buildConfig } from 'payload/config';
|
|
16
16
|
|
|
17
17
|
export default buildConfig({
|
|
@@ -24,7 +24,7 @@ export default buildConfig({
|
|
|
24
24
|
}
|
|
25
25
|
// highlight-end
|
|
26
26
|
}
|
|
27
|
-
})
|
|
27
|
+
});
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
### Aliasing server-only modules
|
|
@@ -52,16 +52,17 @@ You may rely on server-only packages such as the above to perform logic in acces
|
|
|
52
52
|
<br/><br/>
|
|
53
53
|
|
|
54
54
|
`collections/Subscriptions/index.js`
|
|
55
|
-
```
|
|
55
|
+
```ts
|
|
56
|
+
import { CollectionConfig } from 'payload/types';
|
|
56
57
|
import createStripeSubscription from './hooks/createStripeSubscription';
|
|
57
58
|
|
|
58
|
-
const Subscription = {
|
|
59
|
+
const Subscription: CollectionConfig = {
|
|
59
60
|
slug: 'subscriptions',
|
|
60
61
|
hooks: {
|
|
61
62
|
beforeChange: [
|
|
62
63
|
createStripeSubscription,
|
|
63
64
|
]
|
|
64
|
-
}
|
|
65
|
+
},
|
|
65
66
|
fields: [
|
|
66
67
|
{
|
|
67
68
|
name: 'stripeSubscriptionID',
|
|
@@ -69,7 +70,7 @@ const Subscription = {
|
|
|
69
70
|
required: true,
|
|
70
71
|
}
|
|
71
72
|
]
|
|
72
|
-
}
|
|
73
|
+
};
|
|
73
74
|
|
|
74
75
|
export default Subscription;
|
|
75
76
|
```
|
|
@@ -49,7 +49,7 @@ To utilize your API key while interacting with the REST or GraphQL API, add the
|
|
|
49
49
|
|
|
50
50
|
**For example, using Fetch:**
|
|
51
51
|
|
|
52
|
-
```
|
|
52
|
+
```ts
|
|
53
53
|
const response = await fetch("http://localhost:3000/api/pages", {
|
|
54
54
|
headers: {
|
|
55
55
|
Authorization: `${collection.labels.singular} API-Key ${YOUR_API_KEY}`,
|
|
@@ -77,8 +77,10 @@ Function that accepts one argument, containing `{ req, token, user }`, that allo
|
|
|
77
77
|
|
|
78
78
|
Example:
|
|
79
79
|
|
|
80
|
-
```
|
|
81
|
-
{
|
|
80
|
+
```ts
|
|
81
|
+
import { CollectionConfig } from 'payload/types';
|
|
82
|
+
|
|
83
|
+
const Customers: CollectionConfig = {
|
|
82
84
|
slug: 'customers',
|
|
83
85
|
auth: {
|
|
84
86
|
forgotPassword: {
|
|
@@ -104,7 +106,7 @@ Example:
|
|
|
104
106
|
// highlight-end
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
}
|
|
109
|
+
};
|
|
108
110
|
```
|
|
109
111
|
|
|
110
112
|
<Banner type="warning">
|
|
@@ -123,7 +125,7 @@ Similarly to the above `generateEmailHTML`, you can also customize the subject o
|
|
|
123
125
|
|
|
124
126
|
Example:
|
|
125
127
|
|
|
126
|
-
```
|
|
128
|
+
```ts
|
|
127
129
|
{
|
|
128
130
|
slug: 'customers',
|
|
129
131
|
auth: {
|
|
@@ -148,8 +150,11 @@ Function that accepts one argument, containing `{ req, token, user }`, that allo
|
|
|
148
150
|
|
|
149
151
|
Example:
|
|
150
152
|
|
|
151
|
-
```
|
|
152
|
-
{
|
|
153
|
+
```ts
|
|
154
|
+
import { CollectionConfig } from 'payload/types';
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
const Customers: CollectionConfig = {
|
|
153
158
|
slug: 'customers',
|
|
154
159
|
auth: {
|
|
155
160
|
verify: {
|
|
@@ -163,7 +168,7 @@ Example:
|
|
|
163
168
|
// highlight-end
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
|
-
}
|
|
171
|
+
};
|
|
167
172
|
```
|
|
168
173
|
|
|
169
174
|
<Banner type="warning">
|
|
@@ -182,7 +187,7 @@ Similarly to the above `generateEmailHTML`, you can also customize the subject o
|
|
|
182
187
|
|
|
183
188
|
Example:
|
|
184
189
|
|
|
185
|
-
```
|
|
190
|
+
```ts
|
|
186
191
|
{
|
|
187
192
|
slug: 'customers',
|
|
188
193
|
auth: {
|
|
@@ -17,7 +17,7 @@ The Access operation returns what a logged in user can and can't do with the col
|
|
|
17
17
|
`GET http://localhost:3000/api/access`
|
|
18
18
|
|
|
19
19
|
Example response:
|
|
20
|
-
```
|
|
20
|
+
```ts
|
|
21
21
|
{
|
|
22
22
|
canAccessAdmin: true,
|
|
23
23
|
collections: {
|
|
@@ -54,7 +54,7 @@ Example response:
|
|
|
54
54
|
|
|
55
55
|
**Example GraphQL Query**:
|
|
56
56
|
|
|
57
|
-
```
|
|
57
|
+
```graphql
|
|
58
58
|
query {
|
|
59
59
|
Access {
|
|
60
60
|
pages {
|
|
@@ -75,7 +75,7 @@ Returns either a logged in user with token or null when there is no logged in us
|
|
|
75
75
|
`GET http://localhost:3000/api/[collection-slug]/me`
|
|
76
76
|
|
|
77
77
|
Example response:
|
|
78
|
-
```
|
|
78
|
+
```ts
|
|
79
79
|
{
|
|
80
80
|
user: { // The JWT "payload" ;) from the logged in user
|
|
81
81
|
email: 'dev@payloadcms.com',
|
|
@@ -90,7 +90,7 @@ Example response:
|
|
|
90
90
|
|
|
91
91
|
**Example GraphQL Query**:
|
|
92
92
|
|
|
93
|
-
```
|
|
93
|
+
```graphql
|
|
94
94
|
query {
|
|
95
95
|
Me[collection-singular-label] {
|
|
96
96
|
user {
|
|
@@ -106,7 +106,7 @@ query {
|
|
|
106
106
|
Accepts an `email` and `password`. On success, it will return the logged in user as well as a token that can be used to authenticate. In the GraphQL and REST APIs, this operation also automatically sets an HTTP-only cookie including the user's token. If you pass an Express `res` to the Local API operation, Payload will set a cookie there as well.
|
|
107
107
|
|
|
108
108
|
**Example REST API login**:
|
|
109
|
-
```
|
|
109
|
+
```ts
|
|
110
110
|
const res = await fetch('http://localhost:3000/api/[collection-slug]/login', {
|
|
111
111
|
method: 'POST',
|
|
112
112
|
headers: {
|
|
@@ -137,7 +137,7 @@ const json = await res.json();
|
|
|
137
137
|
|
|
138
138
|
**Example GraphQL Mutation**:
|
|
139
139
|
|
|
140
|
-
```
|
|
140
|
+
```graphql
|
|
141
141
|
mutation {
|
|
142
142
|
login[collection-singular-label](email: "dev@payloadcms.com", password: "yikes") {
|
|
143
143
|
user {
|
|
@@ -151,7 +151,7 @@ mutation {
|
|
|
151
151
|
|
|
152
152
|
**Example Local API login**:
|
|
153
153
|
|
|
154
|
-
```
|
|
154
|
+
```ts
|
|
155
155
|
const result = await payload.login({
|
|
156
156
|
collection: '[collection-slug]',
|
|
157
157
|
data: {
|
|
@@ -166,7 +166,7 @@ const result = await payload.login({
|
|
|
166
166
|
As Payload sets HTTP-only cookies, logging out cannot be done by just removing a cookie in JavaScript, as HTTP-only cookies are inaccessible by JS within the browser. So, Payload exposes a `logout` operation to delete the token in a safe way.
|
|
167
167
|
|
|
168
168
|
**Example REST API logout**:
|
|
169
|
-
```
|
|
169
|
+
```ts
|
|
170
170
|
const res = await fetch('http://localhost:3000/api/[collection-slug]/logout', {
|
|
171
171
|
method: 'POST',
|
|
172
172
|
headers: {
|
|
@@ -192,7 +192,7 @@ This operation requires a non-expired token to send back a new one. If the user'
|
|
|
192
192
|
If successful, this operation will automatically renew the user's HTTP-only cookie and will send back the updated token in JSON.
|
|
193
193
|
|
|
194
194
|
**Example REST API token refresh**:
|
|
195
|
-
```
|
|
195
|
+
```ts
|
|
196
196
|
const res = await fetch('http://localhost:3000/api/[collection-slug]/refresh-token', {
|
|
197
197
|
method: 'POST',
|
|
198
198
|
headers: {
|
|
@@ -239,18 +239,18 @@ mutation {
|
|
|
239
239
|
If your collection supports email verification, the Verify operation will be exposed which accepts a verification token and sets the user's `_verified` property to `true`, thereby allowing the user to authenticate with the Payload API.
|
|
240
240
|
|
|
241
241
|
**Example REST API user verification**:
|
|
242
|
-
```
|
|
242
|
+
```ts
|
|
243
243
|
const res = await fetch(`http://localhost:3000/api/[collection-slug]/verify/${TOKEN_HERE}`, {
|
|
244
244
|
method: 'POST',
|
|
245
245
|
headers: {
|
|
246
246
|
'Content-Type': 'application/json',
|
|
247
247
|
},
|
|
248
|
-
})
|
|
248
|
+
});
|
|
249
249
|
```
|
|
250
250
|
|
|
251
251
|
**Example GraphQL Mutation**:
|
|
252
252
|
|
|
253
|
-
```
|
|
253
|
+
```graphql
|
|
254
254
|
mutation {
|
|
255
255
|
verifyEmail[collection-singular-label](token: "TOKEN_HERE")
|
|
256
256
|
}
|
|
@@ -258,7 +258,7 @@ mutation {
|
|
|
258
258
|
|
|
259
259
|
**Example Local API verification**:
|
|
260
260
|
|
|
261
|
-
```
|
|
261
|
+
```ts
|
|
262
262
|
const result = await payload.verifyEmail({
|
|
263
263
|
collection: '[collection-slug]',
|
|
264
264
|
token: 'TOKEN_HERE',
|
|
@@ -272,7 +272,7 @@ If a user locks themselves out and you wish to deliberately unlock them, you can
|
|
|
272
272
|
To restrict who is allowed to unlock users, you can utilize the [`unlock`](/docs/access-control/overview#unlock) access control function.
|
|
273
273
|
|
|
274
274
|
**Example REST API unlock**:
|
|
275
|
-
```
|
|
275
|
+
```ts
|
|
276
276
|
const res = await fetch(`http://localhost:3000/api/[collection-slug]/unlock`, {
|
|
277
277
|
method: 'POST',
|
|
278
278
|
headers: {
|
|
@@ -291,7 +291,7 @@ mutation {
|
|
|
291
291
|
|
|
292
292
|
**Example Local API unlock**:
|
|
293
293
|
|
|
294
|
-
```
|
|
294
|
+
```ts
|
|
295
295
|
const result = await payload.unlock({
|
|
296
296
|
collection: '[collection-slug]',
|
|
297
297
|
})
|
|
@@ -306,7 +306,7 @@ The link to reset the user's password contains a token which is what allows the
|
|
|
306
306
|
By default, the Forgot Password operations send users to the Payload Admin panel to reset their password, but you can customize the generated email to send users to the frontend of your app instead by [overriding the email HTML](/docs/authentication/config#forgot-password).
|
|
307
307
|
|
|
308
308
|
**Example REST API Forgot Password**:
|
|
309
|
-
```
|
|
309
|
+
```ts
|
|
310
310
|
const res = await fetch(`http://localhost:3000/api/[collection-slug]/forgot-password`, {
|
|
311
311
|
method: 'POST',
|
|
312
312
|
headers: {
|
|
@@ -315,7 +315,7 @@ const res = await fetch(`http://localhost:3000/api/[collection-slug]/forgot-pass
|
|
|
315
315
|
body: JSON.stringify({
|
|
316
316
|
email: 'dev@payloadcms.com',
|
|
317
317
|
}),
|
|
318
|
-
})
|
|
318
|
+
});
|
|
319
319
|
```
|
|
320
320
|
|
|
321
321
|
**Example GraphQL Mutation**:
|
|
@@ -328,14 +328,14 @@ mutation {
|
|
|
328
328
|
|
|
329
329
|
**Example Local API forgot password**:
|
|
330
330
|
|
|
331
|
-
```
|
|
331
|
+
```ts
|
|
332
332
|
const token = await payload.forgotPassword({
|
|
333
333
|
collection: '[collection-slug]',
|
|
334
334
|
data: {
|
|
335
335
|
email: 'dev@payloadcms.com',
|
|
336
336
|
},
|
|
337
337
|
disableEmail: false // you can disable the auto-generation of email via local API
|
|
338
|
-
})
|
|
338
|
+
});
|
|
339
339
|
```
|
|
340
340
|
|
|
341
341
|
<Banner type="success">
|
|
@@ -348,7 +348,7 @@ const token = await payload.forgotPassword({
|
|
|
348
348
|
After a user has "forgotten" their password and a token is generated, that token can be used to send to the reset password operation along with a new password which will allow the user to reset their password securely.
|
|
349
349
|
|
|
350
350
|
**Example REST API Reset Password**:
|
|
351
|
-
```
|
|
351
|
+
```ts
|
|
352
352
|
const res = await fetch(`http://localhost:3000/api/[collection-slug]/reset-password`, {
|
|
353
353
|
method: 'POST',
|
|
354
354
|
headers: {
|
|
@@ -358,7 +358,7 @@ const res = await fetch(`http://localhost:3000/api/[collection-slug]/reset-passw
|
|
|
358
358
|
token: 'TOKEN_GOES_HERE'
|
|
359
359
|
password: 'not-today',
|
|
360
360
|
}),
|
|
361
|
-
})
|
|
361
|
+
});
|
|
362
362
|
|
|
363
363
|
const json = await res.json();
|
|
364
364
|
|
|
@@ -379,7 +379,7 @@ const json = await res.json();
|
|
|
379
379
|
|
|
380
380
|
**Example GraphQL Mutation**:
|
|
381
381
|
|
|
382
|
-
```
|
|
382
|
+
```graphql
|
|
383
383
|
mutation {
|
|
384
384
|
resetPassword[collection-singular-label](token: "TOKEN_GOES_HERE", password: "not-today")
|
|
385
385
|
}
|
|
@@ -32,8 +32,10 @@ Every Payload Collection can opt-in to supporting Authentication by specifying t
|
|
|
32
32
|
|
|
33
33
|
Simple example collection:
|
|
34
34
|
|
|
35
|
-
```
|
|
36
|
-
|
|
35
|
+
```ts
|
|
36
|
+
import { CollectionConfig } from 'payload/types';
|
|
37
|
+
|
|
38
|
+
const Admins: CollectionConfig = {
|
|
37
39
|
slug:
|
|
38
40
|
// highlight-start
|
|
39
41
|
auth: {
|
|
@@ -95,7 +97,7 @@ However, if you use `fetch` or similar APIs to retrieve Payload resources from i
|
|
|
95
97
|
|
|
96
98
|
Fetch example, including credentials:
|
|
97
99
|
|
|
98
|
-
```
|
|
100
|
+
```ts
|
|
99
101
|
const response = await fetch('http://localhost:3000/api/pages', {
|
|
100
102
|
credentials: 'include',
|
|
101
103
|
});
|
|
@@ -124,8 +126,8 @@ So, if a user of coolsite.com is logged in and just browsing around on the inter
|
|
|
124
126
|
|
|
125
127
|
To define domains that should allow users to identify themselves via the Payload HTTP-only cookie, use the `csrf` option on the base Payload config to whitelist domains that you trust.
|
|
126
128
|
|
|
127
|
-
`payload.config.
|
|
128
|
-
```
|
|
129
|
+
`payload.config.ts`:
|
|
130
|
+
```ts
|
|
129
131
|
import { buildConfig } from 'payload/config';
|
|
130
132
|
|
|
131
133
|
const config = buildConfig({
|
|
@@ -148,7 +150,7 @@ export default config;
|
|
|
148
150
|
In addition to authenticating via an HTTP-only cookie, you can also identify users via the `Authorization` header on an HTTP request.
|
|
149
151
|
|
|
150
152
|
Example:
|
|
151
|
-
```
|
|
153
|
+
```ts
|
|
152
154
|
const request = await fetch('http://localhost:3000', {
|
|
153
155
|
headers: {
|
|
154
156
|
Authorization: `JWT ${token}`
|
|
@@ -31,8 +31,10 @@ It's often best practice to write your Collections in separate files and then im
|
|
|
31
31
|
|
|
32
32
|
#### Simple collection example
|
|
33
33
|
|
|
34
|
-
```
|
|
35
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import { CollectionConfig } from 'payload/types';
|
|
36
|
+
|
|
37
|
+
const Orders: CollectionConfig = {
|
|
36
38
|
slug: 'orders',
|
|
37
39
|
fields: [
|
|
38
40
|
{
|
|
@@ -47,7 +49,7 @@ const Orders = {
|
|
|
47
49
|
required: true,
|
|
48
50
|
}
|
|
49
51
|
]
|
|
50
|
-
}
|
|
52
|
+
};
|
|
51
53
|
```
|
|
52
54
|
|
|
53
55
|
#### More collection config examples
|
|
@@ -80,8 +82,10 @@ If the function is specified, a Preview button will automatically appear in the
|
|
|
80
82
|
|
|
81
83
|
**Example collection with preview function:**
|
|
82
84
|
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
+
```ts
|
|
86
|
+
import { CollectionConfig } from 'payload/types';
|
|
87
|
+
|
|
88
|
+
const Posts: CollectionConfig = {
|
|
85
89
|
slug: 'posts',
|
|
86
90
|
fields: [
|
|
87
91
|
{
|
|
@@ -118,14 +122,14 @@ Collections support all field types that Payload has to offer—including simple
|
|
|
118
122
|
|
|
119
123
|
You can import collection types as follows:
|
|
120
124
|
|
|
121
|
-
```
|
|
125
|
+
```ts
|
|
122
126
|
import { CollectionConfig } from 'payload/types';
|
|
123
127
|
|
|
124
128
|
// This is the type used for incoming collection configs.
|
|
125
129
|
// Only the bare minimum properties are marked as required.
|
|
126
130
|
```
|
|
127
131
|
|
|
128
|
-
```
|
|
132
|
+
```ts
|
|
129
133
|
import { SanitizedCollectionConfig } from 'payload/types';
|
|
130
134
|
|
|
131
135
|
// This is the type used after an incoming collection config is fully sanitized.
|
|
@@ -28,8 +28,10 @@ As with Collection configs, it's often best practice to write your Globals in se
|
|
|
28
28
|
|
|
29
29
|
#### Simple Global example
|
|
30
30
|
|
|
31
|
-
```
|
|
32
|
-
|
|
31
|
+
```ts
|
|
32
|
+
import { GlobalConfig } from 'payload/types';
|
|
33
|
+
|
|
34
|
+
const Nav: GlobalConfig = {
|
|
33
35
|
slug: 'nav',
|
|
34
36
|
fields: [
|
|
35
37
|
{
|
|
@@ -47,7 +49,9 @@ const Nav = {
|
|
|
47
49
|
]
|
|
48
50
|
},
|
|
49
51
|
]
|
|
50
|
-
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default Nav;
|
|
51
55
|
```
|
|
52
56
|
|
|
53
57
|
#### Global config example
|
|
@@ -78,14 +82,14 @@ Globals support all field types that Payload has to offer—including simple fie
|
|
|
78
82
|
|
|
79
83
|
You can import global types as follows:
|
|
80
84
|
|
|
81
|
-
```
|
|
85
|
+
```ts
|
|
82
86
|
import { GlobalConfig } from 'payload/types';
|
|
83
87
|
|
|
84
88
|
// This is the type used for incoming global configs.
|
|
85
89
|
// Only the bare minimum properties are marked as required.
|
|
86
90
|
```
|
|
87
91
|
|
|
88
|
-
```
|
|
92
|
+
```ts
|
|
89
93
|
import { SanitizedGlobalConfig } from 'payload/types';
|
|
90
94
|
|
|
91
95
|
// This is the type used after an incoming global config is fully sanitized.
|