Create custom endpoint for Users

I did this exactly and the routes aren’t showing up in the role permissions config. When I try adding the route directly in the strapi-server.js file like this instead:

module.exports = (plugin) => {

  plugin.routes['content-api'].routes.push({
    method: 'GET',
    path: '/users/suggested-users',
    handler: 'custom.suggestedUsers',
  })

  return plugin
}

The server crashes with the following error:

[2022-10-20 10:27:26.136] error: Error creating endpoint GET /users/suggested-users: Cannot read properties of undefined (reading 'suggestedUsers')

For clarity, my custom.js file is located here: /extensions/users-permissions/controllers/custom.js

and looks like this (the same as yours)

module.exports = {
  suggestedUsers: async (ctx, next) => {
    console.log('/suggested-users accessed.');
    await next();
  }
};