fix(cms): enforce public publication contract
This commit is contained in:
22
src/utilities/publicationQuery.ts
Normal file
22
src/utilities/publicationQuery.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export type PublicationQueryOptions = Readonly<{
|
||||
draft: boolean
|
||||
overrideAccess: boolean
|
||||
}>
|
||||
|
||||
const publicPublicationQuery = Object.freeze({
|
||||
draft: false,
|
||||
overrideAccess: false,
|
||||
}) satisfies PublicationQueryOptions
|
||||
|
||||
const previewPublicationQuery = Object.freeze({
|
||||
draft: true,
|
||||
overrideAccess: true,
|
||||
}) satisfies PublicationQueryOptions
|
||||
|
||||
/**
|
||||
* Keeps public Local API reads access-controlled while allowing the authenticated
|
||||
* Next.js draft-mode route to intentionally load the latest draft versions.
|
||||
*/
|
||||
export function getPublicationQueryOptions(isPreview: boolean): PublicationQueryOptions {
|
||||
return isPreview ? previewPublicationQuery : publicPublicationQuery
|
||||
}
|
||||
Reference in New Issue
Block a user