35 lines
667 B
TypeScript
35 lines
667 B
TypeScript
import { draftMode } from 'next/headers';
|
|
import { redirect } from 'next/navigation';
|
|
import { getPayload } from 'payload';
|
|
import config from '@payload-config';
|
|
|
|
export async function GET(request: Request) {
|
|
const { searchParams } = new URL(request.url);
|
|
|
|
const slug = searchParams.get('slug');
|
|
|
|
if (!slug)
|
|
return new Response('Missing slug', {
|
|
status: 400
|
|
});
|
|
|
|
const payload = await getPayload({
|
|
config
|
|
});
|
|
|
|
const { user } = await payload.auth({
|
|
headers: request.headers
|
|
});
|
|
|
|
if (!user)
|
|
return new Response('Unauthorized', {
|
|
status: 401
|
|
});
|
|
|
|
const draft = await draftMode();
|
|
|
|
draft.enable();
|
|
|
|
// redirect(`/${slug}`);
|
|
redirect('/');
|
|
} |