Erste brauchbare Version
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { cookies, headers } from 'next/headers';
|
||||
import { getPayload, type Where } from 'payload';
|
||||
import config from '@payload-config';
|
||||
|
||||
|
||||
export async function getPreview() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
let isPreview = cookieStore.get('payload-preview')?.value !== undefined;
|
||||
|
||||
if (isPreview) {
|
||||
const payload = await getPayload({ config });
|
||||
|
||||
const headersList = await headers();
|
||||
|
||||
const { user } = await payload.auth({
|
||||
headers: headersList
|
||||
});
|
||||
|
||||
if (!user)
|
||||
isPreview = false;
|
||||
}
|
||||
|
||||
const where: Where = {};
|
||||
|
||||
if (!isPreview)
|
||||
where._status = {
|
||||
equals: 'published'
|
||||
};
|
||||
|
||||
return {
|
||||
isPreview,
|
||||
where
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user