I would like to always add the createdBy and updatedBy  fields, to get the information I also always see in the admin panel.
As per guide, How to populate creator fields | Strapi Documentation I do two things:
- in src/api/tarif/content-types/tarif/schema.json
"options": {
    "draftAndPublish": false,
    "populateCreatorFields": true
  },
2.in src/api/tarif/routes/tarif.ts  add to middlewares:
export default factories.createCoreRouter('api::tarif.tarif', {
  config: {
    find: {
            middlewares: [
                async (ctx, next) => {
                    if (!ctx.query.populate) {
                      ctx.query.populate = ["createdBy", "updatedBy"];
                    }
                    await next();
                  },
              ```
calling `{{baseUrl}}/api/tarifs/:id` I get as result:
```js
{
    "data": {
        "id": 1,
        "attributes": {
  ...
            "subSubSectionID": "",
            "createdAt": "2024-03-08T17:57:12.185Z",
            "updatedAt": "2024-03-20T15:58:23.635Z",
            "markedForDeletion": false,
            "createdBy": {
                "data": null
            },
            "updatedBy": {
                "data": null
            }
        }
    },
    "meta": {}
}
The calling user has the find and findOne role granted, on users-permissions.
What am I doing wrong?
This topic has been created from a Discord post (1220311466742124594) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord