Skip to content

Commit 1c24b34

Browse files
Add allowedFields configuration option to the Users & Permissions plugin documentation (#1716)
* add register configuration * Add template for migration guide * Apply Ben's suggestion Co-authored-by: Ben Irvin <[email protected]> * Complete migration guide * Reword configuration instructions * Fix incorrectly updated 4.6 → 4.7 migration guide * Fix inadvertently updated h1 in 4.7 migration guide * Remove Rebuild/restart commands in 4.6 mig. already handled in `main` --------- Co-authored-by: Ben Irvin <[email protected]>
1 parent 6204512 commit 1c24b34

File tree

3 files changed

+159
-3
lines changed

3 files changed

+159
-3
lines changed

docusaurus/docs/dev-docs/migration-guides.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ sidebarDepth: 0
88

99
# Migration guides
1010

11-
Migrations are necessary when upgrades to Strapi include breaking changes. The migration guides are sequential, meaning if there is more than 1 migration guide between your current version and the latest release, follow each guide in order. If there is no specific migration guide between your current version and the latest release follow the [Upgrade Strapi guide](/dev-docs/update-version.md).
11+
Migrations are necessary when upgrades to Strapi include breaking changes. The migration guides are sequential, meaning if there is more than 1 migration guide between your current version and the latest release, follow each guide in order.
12+
13+
If there is no specific migration guide between your current version and the latest release, you only need to follow the [guide to upgrade Strapi](/dev-docs/update-version.md).
1214

1315
:::caution
1416
[Plugins extension](/dev-docs/plugins/users-permissions) that create custom code or modify existing code will need to be updated and compared to the changes in the repository. Not updating the plugin extensions could break the application.
@@ -25,6 +27,7 @@ Migrations are necessary when upgrades to Strapi include breaking changes. The m
2527
- [Migration guide from 4.4.5 to 4.5.1](/dev-docs/migration/v4/migration-guide-4.4.5-to-4.5.1)
2628
- [Migration guide from 4.5.1 to 4.6.1](/dev-docs/migration/v4/migration-guide-4.5.1-to-4.6.1)
2729
- [Migration guide from 4.6.1 to 4.7.0](/dev-docs/migration/v4/migration-guide-4.6.1-to-4.7.0)
30+
- [Migration guide from 4.10.1 to 4.11.0](/dev-docs/migration/v4/migration-guide-4.10.1-to-4.11.0)
2831

2932
## v3 to v4 migration guides
3033

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Migrate from 4.7.1+ to 4.11.0
3+
description: Learn how you can migrate your Strapi application from 4.7.1+ to 4.11.0.
4+
displayed_sidebar: devDocsSidebar
5+
---
6+
7+
import BuildCommand from '/docs/snippets/build-npm-yarn.md'
8+
import DevelopCommand from '/docs/snippets/develop-npm-yarn.md'
9+
10+
# v4.10.1+ to v4.11.0 migration guide
11+
12+
The Strapi v4.10.1+ to v4.11.0 migration guide upgrades v4.10.1+ to v4.11.0.
13+
14+
:::note
15+
This migration guide is optional and only concerns Strapi projects that are currently accepting additional, custom user fields (i.e., other than the email, username, and password fields) on their [Users and Permissions plugin](/dev-docs/plugins/users-permissions) registration system.
16+
:::
17+
18+
In Strapi v4.11+, the new user registration system in the Users & Permissions plugin only accepts email, username, and password fields by default. If your Strapi application has added any other custom user fields that your new registration form needs to accept, you must add them to the `allowedFields` configuration.
19+
20+
The migration guide consists of:
21+
22+
- Upgrading the application dependencies
23+
- Adding the additional custom fields to allow in the Users & Permissions plugin
24+
- Reinitializing the application
25+
26+
## Upgrading the application dependencies to 4.11.0
27+
28+
:::prerequisites
29+
Stop the server before starting the upgrade.
30+
:::
31+
32+
1. Upgrade all of the Strapi packages in `package.json` to `4.11.0`:
33+
34+
```json title="package.json"
35+
36+
{
37+
// ...
38+
"dependencies": {
39+
"@strapi/strapi": "4.11.0",
40+
"@strapi/plugin-users-permissions": "4.11.0",
41+
"@strapi/plugin-i18n": "4.11.0"
42+
// ...
43+
}
44+
}
45+
```
46+
47+
2. Save the edited `package.json` file.
48+
49+
3. Run either `yarn` or `npm install` to install the new version.
50+
51+
:::tip
52+
If the operation doesn't work, try removing your `yarn.lock` or `package-lock.json`. If that doesn't help, remove the `node_modules` folder as well and try again.
53+
:::
54+
55+
## Allow additional custom fields in the Users & Permissions plugin registration
56+
57+
The Users & Permissions plugin registration system in Strapi v4.11 only accepts email, username, and password fields by default. If additional fields were added to your user model and need to be accepted on registration, add these fields to the `allowedFields` in the `register` configuration option, otherwise the fields will be ignored.
58+
59+
For example, if you have added a field called `nickname` that you wish to accept from the user, update your configuration object as follows:
60+
61+
<Tabs groupId="js-ts">
62+
63+
<TabItem value="javascript" label="JavaScript">
64+
65+
```js title="./config/plugins.js"
66+
module.exports = ({ env }) => ({
67+
// ...
68+
"users-permissions": {
69+
config: {
70+
register: {
71+
allowedFields: ["nickname"],
72+
},
73+
},
74+
},
75+
// ...
76+
});
77+
```
78+
79+
</TabItem>
80+
81+
<TabItem value="typescript" label="TypeScript">
82+
83+
```ts title="./config/plugins.ts"
84+
export default ({ env }) => ({
85+
// ...
86+
"users-permissions": {
87+
config: {
88+
register: {
89+
allowedFields: ["nickname"],
90+
},
91+
},
92+
},
93+
// ...
94+
});
95+
```
96+
97+
</TabItem>
98+
99+
</Tabs>
100+
101+
## Rebuild the application
102+
103+
<BuildCommand components={props.components} />
104+
105+
## Restart the application
106+
107+
<DevelopCommand components={props.components} />

docusaurus/docs/dev-docs/plugins/users-permissions.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,58 @@ Setting JWT expiry for more than 30 days is **not recommended** due to security
201201

202202
### Registration
203203

204-
Creates a new user in the database with a default role as 'registered'.
204+
#### Configuration
205+
206+
The Users and Permissions plugin only accepts email, username, and password fields by default. If additional fields were added to your user model and need to be accepted on registration, add these fields to the `allowedFields` in the `register` configuration option, otherwise the fields will be ignored.
207+
208+
For example, if you have added a field called `nickname` that you wish to accept from the user, update your configuration object as follows:
209+
210+
<Tabs groupId="js-ts">
211+
212+
<TabItem value="javascript" label="JavaScript">
213+
214+
```js title="./config/plugins.js"
215+
module.exports = ({ env }) => ({
216+
// ...
217+
"users-permissions": {
218+
config: {
219+
register: {
220+
allowedFields: ["nickname"],
221+
},
222+
},
223+
},
224+
// ...
225+
});
226+
```
227+
228+
</TabItem>
229+
230+
<TabItem value="typescript" label="TypeScript">
231+
232+
```ts title="./config/plugins.ts"
233+
export default ({ env }) => ({
234+
// ...
235+
"users-permissions": {
236+
config: {
237+
register: {
238+
allowedFields: ["nickname"],
239+
},
240+
},
241+
},
242+
// ...
243+
});
244+
```
245+
246+
</TabItem>
247+
248+
</Tabs>
205249

206250
#### Usage
207251

252+
Creates a new user in the database with a default role as 'registered'.
253+
208254
```js
209-
import axios from 'axios';
255+
import axios from "axios";
210256

211257
// Request API.
212258
// Add your own code here to customize or restrict how the public can register new users.

0 commit comments

Comments
 (0)