Skip to content

Invalid URL on redirectToPreviewURL() #90

@bymoe

Description

@bymoe

Getting TypeError: Invalid URL on redirectToPreviewURL on the Next.js preview api route.

Screenshot 2024-01-05 at 3 39 01 PM

Versions

  • @prismicio/next: ^1.5.0
  • next: 13.1.6
  • node: 16.14.2

Reproduction

Just following the simplest Next.js documentation to enable previews:
On api/preview.ts:

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const client = Client({ req });
  setPreviewData({ req, res });
  await redirectToPreviewURL({
    req,
    res,
    client,
    linkResolver: previewLinkResolver,
  });
}

Steps to reproduce

yarn dev then access any preview link. e.g. /api/preview?token=:token1&documentId=:id

What is expected?

redirectToPreviewURL shouldn't error. Afaik latest prismic-next version works fine with Next.js 13

What is actually happening?

Editing the document on Prismic and then clicking the "View" redirects just fine to my local preview route, but redirectToPreviewURL errors with 500 and unable to view anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions