V4.0.0 Sanitize user data

v.4.15.0

"use strict";
const utils = require("@strapi/utils");
const { santize } = utils;

const { ForbiddenError } = utils.errors;

/**
 *  project controller
 */

const { createCoreController } = require("@strapi/strapi").factories;

module.exports = createCoreController("api::project.project", ({ strapi }) => ({
  async find(ctx) {
    const { user } = ctx.state;
    const { auth } = ctx.state;
    if (!user) throw new ForbiddenError("You are not authorized");

    const entities = await strapi
      .service("api::project.project")
      .myCustomEntityService(user);

    return await Promise.all(
      entities.map(async (entity) => ({
        ...entity,
        owner: await utils.sanitize.contentAPI.output(
          entity.owner,
          strapi.getModel("plugin::users-permissions.user"),
          { auth }
        ),
      }))
    );
  },
}));
1 Like