next-drupal
next-drupal copied to clipboard
context.preview returns undefined
I tried to implement simmillar logic to this ticket https://github.com/chapter-three/next-drupal/issues/23 . But no matter what i do, context.preview is undefined.
I also have configured preview.ts file:
import { NextApiRequest, NextApiResponse } from 'next'
import { drupal } from 'lib/drupal'
export default async function handler(
request: NextApiRequest,
response: NextApiResponse
) {
// @TODO FIX ANY ERROR
const anyResponse = response as any
return await drupal.preview(request, anyResponse)
}
Because of this, I cannot make preview work for unpublished content.
@Kerchik Is this on local? It's probably the cookie not being set when in an iframe. Can you try the following where you create the DrupalClient?
export const drupal = new DrupalClient(
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
{
forceIframeSameSiteCookie: process.env.NODE_ENV === "development", // <-------
}
)
From the docs:
If you're running your site in development and the host address is different from the iframe preview, you might run into issues with SameSite cookies.
You can read more about this here: https://next-drupal.org/docs/configuration#forceiframesamesitecookie
@shadcn Yes it happens on local, but even when I add forceIframeSameSiteCookie preopert context.preview still returns undefined:
import { DrupalClient } from 'next-drupal'
export const drupal = new DrupalClient(
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
{
auth: {
clientId: process.env.DRUPAL_CLIENT_ID,
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
},
previewSecret: process.env.DRUPAL_PREVIEW_SECRET,
forceIframeSameSiteCookie: true,
}
)
Hmm, what happens if you copy the iframe URL and open it in a new tab? Does it enable preview?
@shadcn No, context.preview is still undefined
@Kerchik Did you figure this out?