New content-type fields for users-permissions.user aren't preserved

System Information
  • Strapi Version: 4.11.2
  • Operating System: Manjaro 23.0.0
  • Database: Postgres
  • Node Version: v18.16.0
  • NPM Version: 9.7.2
  • Yarn Version: 1.22.19

I recently upgraded from Strapi 4.9.0 to 4.11.2. In doing so, I’ve lost the ability for custom fields in users-permissions.user. When I create a new field or fields on the user content-type, the changes are immediately lost in the admin UI.

There are no errors in the console.

Welcome back!
To manage your project πŸš€, go to the administration panel at:
http://localhost:1337/admin

To access the server ⚑, go to:
http://localhost:1337

[2023-06-27 04:45:29.946] http: GET plugin:plugin/admin/plugins/content-type-builder/content-types/plugin::users-permissions.user (24 ms) 200
[2023-06-27 04:45:30.114] http: GET /admin/project-type (8 ms) 200
[2023-06-27 04:45:30.247] http: POST /admin/renew-token (11 ms) 200
[2023-06-27 04:45:30.253] http: GET /admin/init (4 ms) 200
[2023-06-27 04:45:30.431] http: GET /admin/users/me (66 ms) 200
[2023-06-27 04:45:30.450] http: GET /admin/information (88 ms) 200
[2023-06-27 04:45:30.457] http: GET /admin/users/me/permissions (94 ms) 200
[2023-06-27 04:45:30.494] http: GET /i18n/locales (30 ms) 200
[2023-06-27 04:45:30.580] http: GET /content-type-builder/components (28 ms) 200
[2023-06-27 04:45:30.595] http: GET /content-type-builder/reserved-names (37 ms) 200
[2023-06-27 04:45:30.612] http: GET /content-type-builder/content-types (57 ms) 200
[2023-06-27 04:48:16.033] http: GET plugin:plugin/admin/plugins/content-type-builder/content-types/plugin::users-permissions.user (2 ms) 200
[2023-06-27 04:48:16.173] http: GET /admin/project-type (2 ms) 200
[2023-06-27 04:48:16.286] http: POST /admin/renew-token (3 ms) 200
[2023-06-27 04:48:16.290] http: GET /admin/init (3 ms) 200
[2023-06-27 04:48:16.437] http: GET /admin/information (43 ms) 200
[2023-06-27 04:48:16.455] http: GET /admin/users/me (59 ms) 200
[2023-06-27 04:48:16.462] http: GET /admin/users/me/permissions (67 ms) 200
[2023-06-27 04:48:16.485] http: GET /i18n/locales (22 ms) 200
[2023-06-27 04:48:16.571] http: GET /content-type-builder/components (32 ms) 200
[2023-06-27 04:48:16.592] http: GET /content-type-builder/content-types (50 ms) 200
[2023-06-27 04:48:16.610] http: GET /content-type-builder/reserved-names (64 ms) 200
[2023-06-27 04:49:23.467] info: File changed: /home/chris/Documents/strapi/src/extensions/users-permissions/content-types/user/schema.json
[2023-06-27 04:49:23.468] http: PUT /content-type-builder/content-types/plugin::users-permissions.user (41 ms) 201
The server is restarting


 Project information                                                          

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Time               β”‚ Tue Jun 27 2023 04:49:26 GMT-0800 (Alaska Dayli… β”‚
β”‚ Launched in        β”‚ 1182 ms                                          β”‚
β”‚ Environment        β”‚ development                                      β”‚
β”‚ Process PID        β”‚ 347526                                           β”‚
β”‚ Version            β”‚ 4.11.2 (node v18.16.0)                           β”‚
β”‚ Edition            β”‚ Community                                        β”‚
β”‚ Database           β”‚ postgres                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

 Actions available                                                            

Welcome back!
To manage your project πŸš€, go to the administration panel at:
http://localhost:1337/admin

To access the server ⚑, go to:
http://localhost:1337

My first thought was that something with the upgrade was causing the problem. I found out that there was in fact some changes that are likely to be affecting. https://docs.strapi.io/dev-docs/migration/v4/migration-guide-4.10.1-to-4.11.0

I went ahead and installed the new config. (./config/plugins.js)

module.exports = ({
  env
}) => ({
   // (...)
  "users-permissions": {
    config: {
      register: {
        allowedFields: [
          "gigachad",
          "supreme"
        ],
      }
    },
  },
});

After restarting Strapi, I tried creating the two fields again. Unfortunately, I was seeing the same behavior as before, where my changes were immediately lost.

Is there some other migration step that I need to carry out in order to preserve my custom fields?

Update 1. I can’t reproduce the issue in a fresh installation of Strapi 4.11.2. I’m going to dig into the source to see the differences between this fresh install and my problem install.

Update 2. I narrowed down the problem to my custom users-permissions extensions. When I have src/extensions/users-permissions/strapi-server.js present, I’m seeing the problem demonstrated in my original post. I see that src/extensions/users-permissions/content-types/user/schema.json is updated correctly, but the changes are not reflected in the admin UI.

I can work around the issue by modifying src/extensions/users-permissions/server/content-types/user/index.js instead of using the admin UI which modifies src/extensions/users-permissions/content-types/user/schema.json. When I edit that file, the admin UI behaves as expected. However, I don’t know if it’s good to edit that file. Further, I never had to edit that file in previous versions of users-permissions.

I’m pretty confused on this one, but I’ll keep looking for an answer.

Update 3. I suspected that one of the recent Strapi updates introduced breaking changes. Maybe one of https://github.com/strapi/strapi/pull/16333 or chore: remove history & clean up some U&P tests by joshuaellis Β· Pull Request #16992 Β· strapi/strapi Β· GitHub

To test this theory, I decided to run some tests using every version inbetween where I started and where I’m now. When I found a version that no longer worked, I’d know which update broke things.

I didn’t get very far. I realized that even the working version I came from, v4.9.0 had the same error I demonstrated in my original post. This led me to believe that there was something I missed in my custom users-permissions extension. Some of the code I had running in production was not the same as what I was working with in my development environment.

My custom extensions are summarized in another thread, How to allow content access for only Patrons

What I was missing in my development environment was my custom strapi-server.js, which overwrites providers and providers-registry. Without this file, I was overwriting everything with the stock users-permissions strapi-server.js, which introduced the initially described strange behavior.

'use strict';
// src/extensions/users-permissions/strapi-server.js
module.exports = (plugin) => {
    plugin.bootstrap = require('./server/bootstrap');
    plugin.services['providers'] = require('./server/services/providers');
    plugin.services['providers-registry'] = require('./server/services/providers-registry');
    return plugin;
}

I’m up and running with a content type manager that behaves as expected.

1 Like

Thank you for keeping your post updated, I imagine this will be quite helpful for others in the future.

Thank you @ggr247 for not being that person

1 Like