Prismic Preview Mode does not provide preview Refs (Nextjs)

Hi everyone :wave:

I have been having a little bit of struggle with the preview mode. To fetch the unpublished posts, we would need to preview ref, and this is how it is done on the Prismic's NextJS page:

const Preview = async (req, res) => {
const { token: ref, documentId } = req.query;
const redirectUrl = await Client(req)

So within req.query, there should be token, within which I would find the ref and the documentID. In my case, token does not have any items inside it. It is a string. Something similar to this:

https://example-repository.prismic.io/previews/XzjsUxJFIEKGAAAK:XzfX3BVHSOWAzIaf?websitePreviewId=GKHCDOBLDJW

Is there a reason for that? Currently I am fetching the preview string from the prismic cookie that prismic's preview library script automatically adds. But I would love to do it without it and take it right from the query.

Hi @aman, thanks for reaching out about this.

This syntax in Javascript might be a little confusing.

const { token: ref, documentId } = req.query;

What it is doing is retrieving the token from the req.query and assigning it to the variable ref. It is also retrieving the documentId from the req.query. That code snippet is the same as the following:

const ref = req.query.token;
const documentId = req.query.documentId;

So what you are seeing is correct. The token should be the url string that you are seeing. That url string is the preview ref.

This issue has been closed due to inactivity.