Skip to main content

用户与权限插件的 register.allowedFields 配置选项默认值为 []

🌐 The Users & Permissions plugin's register.allowedFields configuration option defaults to []

Page summary:

在 Strapi 5 中,用户与权限插件的 register.allowedFields 默认为空数组,需要显式允许字段,而不是默认接受所有字段。

🌐 In Strapi 5, the Users & Permissions plugin's register.allowedFields defaults to an empty array, requiring explicit field allowlisting instead of accepting all fields by default.

在 Strapi 5 中,Users & Permissions 插件的 register.allowedFields 配置选项默认值为 []

🌐 In Strapi 5, the Users & Permissions plugin's register.allowedFields configuration option defaults to [].

此页面是重大更改数据库的一部分,提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

 Is this breaking change affecting plugins?No
 Is this breaking change automatically handled by a codemod?Yes
(see use-uid-for-config-namespace)

重大变更描述

🌐 Breaking change description

在 Strapi v4 中

默认情况下,注册表单将接受添加到用户内容类型的任何新字段,并且 Strapi 会在启动时警告每个字段。

🌐 Any new fields added to the User content type would be accepted by the registration form by default, and Strapi would warn about each field on startup.

用户可以选择在 config/plugins.js 文件中将 users-permissions.register.allowedFields 设置为他们希望在注册端点上接受的字段数组。例如,[’picture’] 用于在注册时接受图片属性。或者,如果他们不想接受其他任何内容,可以设置一个空数组 []

🌐 The users have the option to set users-permissions.register.allowedFields in the config/plugins.js file to an array of the fields they wanted to accept on their registration endpoint. For example, [’picture’] to accept a picture attribute on registration. Or an empty array [] if they do not want to accept anything else.

然而,如果用户没有设置任何值,即当 allowedFields 未定义时,所有用户字段都被接受。

🌐 However, if users did not set any value, that is, when allowedFields is undefined, all user fields are accepted.

在 Strapi 5 中

未定义的 allowedFields 被视为空数组,并且默认情况下不接受任何字段。用户必须在注册时明确选择允许额外字段。

🌐 An undefined allowedFields is treated as an empty array, and no fields are accepted by default. Users must explicitly choose to allow extra fields on registration.

它在 Strapi 5 中的工作原理

🌐 How it works in Strapi 5

字段 usernameemailpassword 总是被注册端点接受。它们在“用户与权限”功能源代码中被硬编码为 alwaysAllowedKeys。用户内容类型上的任何其他字段必须明确列在 allowedFields 中,否则请求将被拒绝,并返回 400 状态及类似 "Invalid parameters: fieldName" 的错误信息。

🌐 The fields username, email, and password are always accepted by the registration endpoint. They are hardcoded as alwaysAllowedKeys in the Users & Permissions feature source. Any other field on the User content-type must be explicitly listed in allowedFields or the request will be rejected with a 400 status and an error message like "Invalid parameters: fieldName".

迁移

🌐 Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

🌐 This section regroups useful notes and procedures about the introduced breaking change.

手动操作

🌐 Manual procedure

应当由 codemod 来处理此迁移。如果没有,请参考文档了解如何为用户与权限插件注册允许的字段

🌐 A codemod should handle this migration. If not, please refer to the documentation on how to register allowed fields for the Users & Permissions plugin.

要允许在注册时添加额外字段,请更新你的插件配置:

🌐 To allow additional fields on registration, update your plugin configuration:

config/plugins.js
module.exports = {
'users-permissions': {
config: {
register: {
allowedFields: ['firstName', 'lastName'],
},
},
},
};

如果你依赖 Strapi v4 的行为(默认接受所有字段),请在 allowedFields 中列出每个额外字段。未列出的字段将被静默删除或拒绝。

🌐 If you relied on the Strapi v4 behavior (all fields accepted by default), list every extra field in allowedFields. Fields not listed will be silently dropped or rejected.