I am building the site with Remix and try to setup the preview mode
I am using the @prismicio/client v6
export const linkResolver = (doc: PrismicDocument) => {
return '/'
}
export const loader: LoaderFunction = async ({request}) => {
const url = new URL(request.url);
const token = url.searchParams.get("token")
const documentId = url.searchParams.get("documentId")
if (!token) {
throw new Response("No token found.", {
status: 404
});
}
if (!documentId) {
throw new Response("No document Id found.", {
status: 404
});
}
const previewURL = await client.resolvePreviewURL({
defaultURL: '/',
previewToken: token,
documentID: documentId
linkResolver: linkResolver
})
// TODO: redirect the user to preview URL
}
How does Prismic know that I am in preview mode? Which line of code does set the preview cookie?
To my understanding, if the preview cookie is set in place, the client automatically knows that it should fetch preview content. Is this correct?
If so, how can I tell the client to always fetch preview content in my local?
Update: I got the preview cookie work, however, the client doesn't fetch the draft data. Do I need to do something to update my prismic-client setup
import * as prismic from "@prismicio/client"
import {PrismicDocument} from '@prismicio/types';
export const repositoryName = "test-repo"
const endpoint = prismic.getEndpoint(repositoryName)
export const linkResolver = (doc: PrismicDocument) => {
return '/'
}
export const client = prismic.createClient(endpoint, {
accessToken: process.env.PRISMIC_TOKEN
})
I also see that we need to setup the /api/exit-preview.js route. When is this route hit?
Thank you Prismic team!