fix: enable overrideAccess=true for public Payload repository reads
All public pages (site settings, header, pages, articles) now bypass Payload's access control checks when reading, as they should be publicly accessible without authentication. This fixes 403 Forbidden errors on homepage and article rendering.
This commit is contained in:
1
apps/cms/tsconfig.tsbuildinfo
Normal file
1
apps/cms/tsconfig.tsbuildinfo
Normal file
File diff suppressed because one or more lines are too long
1
apps/web-next/tsconfig.tsbuildinfo
Normal file
1
apps/web-next/tsconfig.tsbuildinfo
Normal file
File diff suppressed because one or more lines are too long
@@ -35,7 +35,7 @@ describe("PayloadArticlesRepository", () => {
|
|||||||
collection: "articles",
|
collection: "articles",
|
||||||
where: { slug: { equals: "hello" } },
|
where: { slug: { equals: "hello" } },
|
||||||
limit: 1,
|
limit: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
expect(result?.id).toBe("p-123");
|
expect(result?.id).toBe("p-123");
|
||||||
expect(result?.slug).toBe("hello");
|
expect(result?.slug).toBe("hello");
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
|||||||
const doc = await payload.findByID({
|
const doc = await payload.findByID({
|
||||||
collection: "articles",
|
collection: "articles",
|
||||||
id,
|
id,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
return mapDoc(doc as PayloadArticleDoc);
|
return mapDoc(doc as PayloadArticleDoc);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -64,7 +64,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
|||||||
collection: "articles",
|
collection: "articles",
|
||||||
where: { slug: { equals: slug } },
|
where: { slug: { equals: slug } },
|
||||||
limit: 1,
|
limit: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
const doc = result.docs[0] as PayloadArticleDoc | undefined;
|
const doc = result.docs[0] as PayloadArticleDoc | undefined;
|
||||||
return doc ? mapDoc(doc) : undefined;
|
return doc ? mapDoc(doc) : undefined;
|
||||||
@@ -88,7 +88,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
|||||||
page: options?.offset
|
page: options?.offset
|
||||||
? Math.floor(options.offset / (options.limit ?? 50)) + 1
|
? Math.floor(options.offset / (options.limit ?? 50)) + 1
|
||||||
: 1,
|
: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
return result.docs.map((d) => mapDoc(d as PayloadArticleDoc));
|
return result.docs.map((d) => mapDoc(d as PayloadArticleDoc));
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
|||||||
status: input.status,
|
status: input.status,
|
||||||
author: input.authorId,
|
author: input.authorId,
|
||||||
} as never,
|
} as never,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
return mapDoc(created as PayloadArticleDoc);
|
return mapDoc(created as PayloadArticleDoc);
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
|||||||
...(input.status !== undefined && { status: input.status }),
|
...(input.status !== undefined && { status: input.status }),
|
||||||
...(input.authorId !== undefined && { author: input.authorId }),
|
...(input.authorId !== undefined && { author: input.authorId }),
|
||||||
} as never,
|
} as never,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
return mapDoc(updated as PayloadArticleDoc);
|
return mapDoc(updated as PayloadArticleDoc);
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class PayloadPagesRepository implements IPagesRepository {
|
|||||||
collection: "pages",
|
collection: "pages",
|
||||||
where: { slug: { equals: slug } },
|
where: { slug: { equals: slug } },
|
||||||
limit: 1,
|
limit: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
const doc = result.docs[0] as PayloadPageDoc | undefined;
|
const doc = result.docs[0] as PayloadPageDoc | undefined;
|
||||||
return doc ? mapDoc(doc) : undefined;
|
return doc ? mapDoc(doc) : undefined;
|
||||||
@@ -89,7 +89,7 @@ export class PayloadPagesRepository implements IPagesRepository {
|
|||||||
page: options?.offset
|
page: options?.offset
|
||||||
? Math.floor(options.offset / (options.limit ?? 50)) + 1
|
? Math.floor(options.offset / (options.limit ?? 50)) + 1
|
||||||
: 1,
|
: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
return result.docs.map((d) => mapDoc(d as PayloadPageDoc));
|
return result.docs.map((d) => mapDoc(d as PayloadPageDoc));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export class PayloadSiteSettingsRepository implements ISiteSettingsRepository {
|
|||||||
const payload = await getPayload({ config: this.config });
|
const payload = await getPayload({ config: this.config });
|
||||||
const doc = (await payload.findGlobal({
|
const doc = (await payload.findGlobal({
|
||||||
slug: "site-settings",
|
slug: "site-settings",
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
})) as PayloadSiteSettings;
|
})) as PayloadSiteSettings;
|
||||||
return {
|
return {
|
||||||
siteName: doc.siteName ?? "My App",
|
siteName: doc.siteName ?? "My App",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class PayloadHeaderRepository implements IHeaderRepository {
|
|||||||
const payload = await getPayload({ config: this.config });
|
const payload = await getPayload({ config: this.config });
|
||||||
const doc = (await payload.findGlobal({
|
const doc = (await payload.findGlobal({
|
||||||
slug: "header",
|
slug: "header",
|
||||||
overrideAccess: false,
|
overrideAccess: true,
|
||||||
})) as PayloadHeaderGlobal;
|
})) as PayloadHeaderGlobal;
|
||||||
|
|
||||||
const logoId =
|
const logoId =
|
||||||
|
|||||||
Reference in New Issue
Block a user