Extend user controller in V4

Hello,

I’m currently migrating my strapi installation from v3 to v4.
And, I’m actually stuck on the migration of the user extension.

In V3, I’ve got a file in users-permissions/services/User.js (following this guide : Get currrent logged user with custom data added to the User Collection type)

//extend api/users/me
fetchAuthenticatedUser(id) {
    return strapi
      .query("user", "users-permissions")
      .findOne({ id }, [
        "role",
        "publications",
        "publications.logo",
        "avatar",
        "posts",
      ]); // added restaurants
  },

This allowed me to populate the role of a logged user.

In V4, I know that we need to create a strapi-server.js at the root of user-permissions folder, I try to add this :

module.exports = (plugin) => {

  plugin.controllers.user.me = (id) => {
    return strapi
      .query("users-permissions")
      .findOne({ id }, [
        "role",
        "publications",
        "publications.logo",
        "avatar",
        "posts",
      ]); 
  };

  return plugin;
};

But it told me that the Model users-permissions not found…

This answer that does not look very elegant did the job for me:

Don’t hesitate on replaying if you find better solutions.

Hope it helps.