From eaf4985f0876a7159768d85769a00f79d4e8887a Mon Sep 17 00:00:00 2001 From: Balint Kleri Date: Tue, 11 Jun 2024 22:36:59 +0200 Subject: [PATCH] fix(basic-starter): fetch resource with auth in Draft Mode --- examples/example-router-migration/app/[...slug]/page.tsx | 6 +++++- starters/basic-starter/app/[...slug]/page.tsx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/example-router-migration/app/[...slug]/page.tsx b/examples/example-router-migration/app/[...slug]/page.tsx index 4e61889c..5c7b7464 100644 --- a/examples/example-router-migration/app/[...slug]/page.tsx +++ b/examples/example-router-migration/app/[...slug]/page.tsx @@ -12,6 +12,7 @@ async function getNode(slug: string[]) { const params: JsonApiParams = {} + const isDraftMode = draftMode().isEnabled const draftData = getDraftData() if (draftData.path === path) { @@ -19,7 +20,9 @@ async function getNode(slug: string[]) { } // Translating the path also allows us to discover the entity type. - const translatedPath = await drupal.translatePath(path) + const translatedPath = await drupal.translatePath(path, { + withAuth: isDraftMode, + }) if (!translatedPath) { throw new Error("Resource not found", { cause: "NotFound" }) @@ -34,6 +37,7 @@ async function getNode(slug: string[]) { const resource = await drupal.getResource(type, uuid, { params, + withAuth: isDraftMode, }) if (!resource) { diff --git a/starters/basic-starter/app/[...slug]/page.tsx b/starters/basic-starter/app/[...slug]/page.tsx index 4e61889c..5c7b7464 100644 --- a/starters/basic-starter/app/[...slug]/page.tsx +++ b/starters/basic-starter/app/[...slug]/page.tsx @@ -12,6 +12,7 @@ async function getNode(slug: string[]) { const params: JsonApiParams = {} + const isDraftMode = draftMode().isEnabled const draftData = getDraftData() if (draftData.path === path) { @@ -19,7 +20,9 @@ async function getNode(slug: string[]) { } // Translating the path also allows us to discover the entity type. - const translatedPath = await drupal.translatePath(path) + const translatedPath = await drupal.translatePath(path, { + withAuth: isDraftMode, + }) if (!translatedPath) { throw new Error("Resource not found", { cause: "NotFound" }) @@ -34,6 +37,7 @@ async function getNode(slug: string[]) { const resource = await drupal.getResource(type, uuid, { params, + withAuth: isDraftMode, }) if (!resource) {