Planned preview error

Trying to preview planned release after latest prismic upgrade doesn't return any token to check against the prismic sdk.
So no way to see any planned changes.

Hi @prismic5,

Could you share a little bit more information on the context of the issue you're encountering? How is your preview set up?

Thanks :slight_smile:

sure
I have a api/preview route in next.js project

Here is the code in that api route

import { NextApiRequest, NextApiResponse } from 'next';

import { prismicClient } from 'api/prismic';
import { linkResolver } from 'utils/linkResolver';
import { getStringFromQueryString } from 'utils/querystring';

export default async function preview(req: NextApiRequest, res: NextApiResponse) {
  const ref = getStringFromQueryString(req.query.token);
  const documentId = getStringFromQueryString(req.query.documentId);

  if (!prismicClient) {
    return null;
  }

  if (!ref) {
    return res.status(401).json({ message: 'Missing ref from querystring' });
  }

  // Check the token parameter against the Prismic SDK
  const url = await prismicClient.resolvePreviewURL({
    linkResolver,
    previewToken: ref,
    documentID: documentId,
    defaultURL: '/',
  });

  if (!url) {
    return res.status(401).json({ message: 'Invalid token' });
  }

  // Enable Preview Mode by setting the cookies
  res.setPreviewData({
    ref, // pass the ref to pages so that they can fetch the draft ref
  });

  // Redirect the user to the share endpoint from same origin. This is
  // necessary due to a Chrome bug:
  // https://bugs.chromium.org/p/chromium/issues/detail?id=696204
  res.writeHead(200, { 'Content-Type': 'text/html; charset=UTF-8' });
  res.write(
    `<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; url=${url}" />
      <script>window.location.href = '${url}'</script>
      </head>`
  );

  res.end();
}

The issue is that I get the 401 message Missing ref from querystring and req.query returns emtpy object.

Thank you for sharing :slight_smile: What version of Next are you using?

Next 14

any news @Ezekiel ?

What latest prismic upgrade are you referring to? And is this issue specific to planned releases, i.e. everything else you're trying to preview works fine as is?