You can restrict users to read only documents where a specific field is set to true by using a query constraint in the read access control function. For example, if you have a checkbox field named isPublic, you can return a query constraint like this:
const canReadPage = ({ req: { user } }) => {
if (user) {
return true; // Allow authenticated users
}
// Restrict access to documents where 'isPublic' is true
return {
isPublic: {
equals: true,
},
};
};
In this example, authenticated users can access any documents, while unauthenticated users can only access documents where the isPublic field is set to true.