Skip to content

Commit

Permalink
[B] Previews render saved page when no token
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Mason committed Jan 13, 2023
1 parent 4d3ee36 commit 12bacd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 14 additions & 2 deletions pages/[[...uriSegments]].js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ export async function getStaticProps({ params: { uriSegments }, previewData }) {
);
}

const { sectionHandle: section, typeHandle: type } =
await getEntrySectionTypeByUri(uri, site, previewData?.previewToken);
const entrySectionType = await getEntrySectionTypeByUri(
uri,
site,
previewData?.previewToken
);

// Handle 404 if there is no data
if (!entrySectionType) {
setEdcLog(runId, "404 encountered building for " + uri, "BUILD_ERROR_404");
return {
notFound: true,
};
}

const { sectionHandle: section, typeHandle: type } = entrySectionType;
const entryData = await getEntryData(
uri,
section,
Expand Down
6 changes: 1 addition & 5 deletions pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ const preview = async (req, res) => {
const isPreview = isCraftPreview(query);
const previewToken = query.token || null;

if (!isPreview) {
return res.status(401).json({ message: "Missing Craft Preview header" });
}

if (!query.entryUid) {
return res
.status(401)
Expand All @@ -30,7 +26,7 @@ const preview = async (req, res) => {
}

// Enable Preview Mode by setting the cookies
if (isPreview && previewToken) {
if (previewToken) {
res.setPreviewData({
previewToken,
});
Expand Down

0 comments on commit 12bacd5

Please sign in to comment.