Skip to content

Commit

Permalink
Include draft content when in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Siilwyn committed Apr 18, 2023
1 parent 1aff26d commit 4697e79
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/composables/useFetchContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ export async function useFetchContent({ key = null, query, variables }) {
const runtimeConfig = useRuntimeConfig();
const route = useRoute();
const data = ref(null);
const isPreview =
runtimeConfig.public.baseUrl.includes('localhost') ||
(route.query.preview === 'true' && route.query.previewSecret === runtimeConfig.public.previewSecret);

if (runtimeConfig.public.baseUrl.includes('localhost') ||
(route.query.preview === 'true' && route.query.previewSecret === runtimeConfig.public.previewSecret)
) {
if (isPreview) {
let unsubscribe;

onMounted(async () => {
Expand All @@ -28,14 +29,16 @@ export async function useFetchContent({ key = null, query, variables }) {
});
}

const pageKey =
key ||
const pageKey = key ||
[route.name, ...Object.values(route.params)].filter(Boolean).join('-');

const { data: initialData } = await useAsyncData(pageKey, () => (
$fetch(`https://graphql.datocms.com/`, {
method: 'post',
headers: { 'Authorization': runtimeConfig.public.datoApiToken },
headers: {
'Authorization': runtimeConfig.public.datoApiToken,
'X-Include-Drafts': isPreview,
},
body: {
query,
variables,
Expand Down

0 comments on commit 4697e79

Please sign in to comment.