Hello,
I'm having some problems implementing previews on unpublished documents in production. In development it works as expected no issues what so ever.
my preview code is the same as in the documentation:
const Preview = async (req, res) => {
const { token: ref, documentId } = req.query;
const redirectUrl = await Client(req)
.getPreviewResolver(ref, documentId)
.resolve(linkResolver, "/");
if (!redirectUrl) {
return res.status(401).json({ message: "Invalid token" });
}
res.setPreviewData({ ref });
res.writeHead(302, { Location: `${redirectUrl}` });
res.end();
};
export default Preview;
and the code for slugs I am trying to preview is:
export async function getStaticProps({
params = {},
preview = null,
previewData = {},
}) {
const { uid } = params;
const { ref } = previewData;
const client = Client();
const page = await client.getByUID("project", uid, {
ref: ref ? ref : null,
});
return {
props: {
preview,
page,
},
};
}
I have tried implementations from the examples and nothing seems to be working. Are previews on drafts in production supported? When I log the document in the link resolver I get the draft as expected, if I log the ref in the preview component it logs the correct redirect url and the correct ref. but in the logs of the getStaticProps function, the preview remains on null as well as the previewData.
"next": "9.5.2",
"prismic-javascript": "^3.0.2",
Thanks for your help