#How to restrict read access of a collection based on API key authentication?
7 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
Community-Help:
const fetchArticles = async () => {
return (
await apiClient.get(`short-articles${stringifiedQuery}`, {
headers: {
Authorization: `short-articles API-Key key`,
},
})
).data;
};
const ShortArticles: CollectionConfig = {
slug: "short-articles",
hooks: {
beforeChange: [
({ data, req }) => {
if (data.content) {
data.rawContent = extractTextFromSlate(data.content);
}
},
],
},
versions: {
drafts: true,
},
admin: {
useAsTitle: "title",
group: "Content",
},
access: {
read: ({ req: { user } }) => { return !!user }
},
fields: [
{
name: "title",
type: "text",
required: true,
localized: true,
unique: true,
},
{
name: "content",
type: "richText",
required: true,
localized: true,
},
{
name: "rawContent",
type: "text",
localized: true,
admin: {
hidden: true,
},
},
{
name: "urlPath",
type: "relationship",
relationTo: "paths",
hasMany: false,
required: true,
},
{
name: "branch",
type: "relationship",
relationTo: "branches",
hasMany: false,
required: true,
},
],
};
export default ShortArticles;
do i need to create api key for each collection in this case?
is it possible that i can create one user and use his api key to create access control for my collections?