so I'm using strapi as my backend and made a small script for authorization of some parts of the API, and added a small tweak to the controller
'use strict';
const { sanitizeEntity } = require('strapi-utils');
const finder = require('strapi-utils/lib/finder');
/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
* to customize this controller
*/
module.exports = {
async find(ctx){
const { user } = ctx.state
let entities
if(ctx.query._q){
entities = await strapi.services.order.search({...ctx.query, user: user.id})
} else {
entities = await strapi.services.order.find({...ctx.query, user: user.id})
}
return entities.map(entity => sanitizeEntity(entity, { model: strapi.models.order }))
},
async findOne(ctx){
const {id} = ctx.params
const {user} = ctx.state
const entity = await strapi.services.order.findOne({id, user: user.id})
return sanitizeEntity(entity, { model: strapi.models.order })
}
};
And tweaked everything correctly on the front-end part, but after reloading Next, i get a
Unhandled Runtime Error
TypeError: pino.pretty is not a function
Source
../ecomm-backend/api/order/controllers/order.js (2:27) @ eval
1 | 'use strict';
> 2 | const { sanitizeEntity } = require('strapi-utils');
Once I remove the import of SanitizeEntity the error dissappears but I need it inside the controller. I don't know why it shows a pino pretty error when I don't even use it. Or is this a weird glitch? If someone can help me I'd really appreciate it :)
If you're using Strapi ver > 4, here's how to require it:
const { sanitizeEntity } = require('@strapi/utils');