System Information
- Strapi Version: ^4.10.5
- Operating System: node-18 alpine docker image
- Database: Postgres
- Node Version: 18.something
- NPM Version:
- Yarn Version:
So I have this schema:
{
"kind": "collectionType",
"collectionName": "addresses",
"info": {
"singularName": "address",
"pluralName": "addresses",
"displayName": "Address",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"street": {
"type": "string",
"required": true
},
...
"owner": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.user",
"inversedBy": "addresses"
}
}
}
And I have updated my list endpoint like this:
'use strict';
/**
* address controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::address.address",
({
strapi
}) => ({
async find(ctx) {
console.log('CTDX, ', ctx.state);
const {
filters
} = ctx.query;
ctx.query = {
...ctx.query,
filters: {
...filters,
owner: {
id: ctx.state.user.id
}
}
};
return await super.find(ctx);
}
}));
When I query the endpoint (localhost:1337/api/addresses?populate=*) with authenticated users credentials I
- I don’t see the owner field in the output - why?
- Data is not filtered by where the owner is the authenticated user - I see all the data - why?
- Do I need to also return async findOne to make sure single results are also filtered by authenticated user?
Thank you in advance.