I want to make a middleware that allows only owner of this entry can’t update but it doesnt return error as i expect. Although it runs through is-belong-user policy
Here’s my policy in /config/policies/is-belong-user.js
module.exports = async (ctx, next) => {
const todo = await strapi.services.todos.find({
id: ctx.params.id,
'user_id': ctx.state.user.id,
});
if (todo && todo.length) {
return await next();
}
ctx.unauthorized(`You don't have authorize for this entry`);
};
and Here’s my api/todos/config/schema.graphql
Mutation: {
updateTodo: {
description: 'Update todo detail',
policies: [
'global::is-belong-user',
],
},
}
Can anyone help me. Thanks in advance