We have a site using the Prismic toolbar, and are able to preview content so long as we are logged into the CMS. According to this documentation it should be possible to share this preview with non-Prismic users.
Initially what we found is that https://prismic.link/xxyyzz links are a little malformed, encoding the ampersand in the query string as an html entity &. This meant that nothing worked as the token & document id can't be parsed properly.
Example from the link redirect page;
<html>
<head>
<title>prismic.io Preview</title>
<link rel="icon" type="image/png" href="/...2eb5115/images/favicon.png">
<meta property="og:title" content="prismic.io Preview"/>
<meta property="og:description" content="The times, they’re a-changing"/>
<meta property="og:image" content="https://prismic-io.s3.amazonaws.com/prismic-io/previews/my-repo-name/YE_RlBIAAGA21qdB~YEk7shIAACEAum9t/previewYE_RlBIAAGA21qdB~YEk7shIAACEAum9t.jpg"/>
</head>
<body>
<script type="text/javascript">
function setCookie(name, value, days) {
var d = new Date;
d.setTime(d.getTime() + 24*60*60*1000*days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString() + ";SameSite=None" + ";Secure";
}
setCookie("io.prismic.previewSession", "YE_RlBIAAGA21qdB~YEk7shIAACEAum9t", 1);
window.location = "https://localhost:8000/preview?token=https%3A%2F%2Fmy-repo-name.prismic.io%2Fpreviews%2FYE_CqxIAACEA1mUO%3AYFBBghMAACYAbv5M%3FwebsitePreviewId%3DYEk7shIAACEAum9t&documentId=XXXXXXXYYYYYY";
^ This
</script>
</body>
</html>
We implemented a workaround where we first replaced the & character with a regular & and then parsed it. What we're getting now is just the published content displaying instead of the draft content.
Everything renders correctly, but we are seeing the published content.
In the above documentation there is a section about preview cookies, however all of the links in it are 404s, so it's possible there is something I'm missing here.
Are you including the Primic preview toolbar on every page? You need to make sure to add it on your 404 pages if you want to be able to use the shareable preview. This is mandatory to share content that has not yet been published.
Regarding the troubleshooting guide, what is the 'preview script' mentioned in the first step?
Can you see the preview cookie in the browser? io.prismic.previewSession cookie is present, but the this doc says it should be io.prismic.preview?
Token content looks fine.
How to test in the Rest API
It seems to be returning draft data when I take the preview token and call the document search api with that ref, so it would appear the problem lies somewhere in javascript.
Are you using a kit?
No, just @prismicio/client and prismic-reactjs, although I've been able to reproduce the same issue with the reactjs-starter project.
Did you configure a route to handle redirection? Is this route using the link resolver?
Our app is React-only, this looks like a server-side Node implementation?
Preview script: It's a toolbar script that you already included on every page, as you mentioned.
preview cookie: You can see two cookies but in different hosts under the browser's cookies section. Ideally, you will see io.prismic.preview cookie on the localhost. And io.prismic.previewSession on your repo URL.
You are using the correct Kit.
You won't need to configure a route to handle rejection like the example given. It's in Node. But you need to include the Link Resolver route to your application like given here.. are you implementing this?
Thanks @Priyanka, I'm not seeing the io.prismic.preview cookie on localhost when opening a sharable preview link (but I do see it in browsers which are logged in to Prismic CMS).
I'm not using routing (e.g. react-router), but instead just checking if the browser's location.pathname is '/preview' in the top level component, e.g;
It redirects to the correct page, but getPreviewResolver does not appear to be setting any cookie, so only the published content is displayed. Is there something else missing?
hi there? I was wondering if there's any update regarding this issue, as i think we may have similar problem. We're unable to share a link to preview with draft content. TIA