Skip to content

Commit eaf4985

Browse files
committed
fix(basic-starter): fetch resource with auth in Draft Mode
1 parent f56c243 commit eaf4985

File tree

2 files changed

+10
-2
lines changed
  • examples/example-router-migration/app/[...slug]
  • starters/basic-starter/app/[...slug]

2 files changed

+10
-2
lines changed

examples/example-router-migration/app/[...slug]/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ async function getNode(slug: string[]) {
1212

1313
const params: JsonApiParams = {}
1414

15+
const isDraftMode = draftMode().isEnabled
1516
const draftData = getDraftData()
1617

1718
if (draftData.path === path) {
1819
params.resourceVersion = draftData.resourceVersion
1920
}
2021

2122
// Translating the path also allows us to discover the entity type.
22-
const translatedPath = await drupal.translatePath(path)
23+
const translatedPath = await drupal.translatePath(path, {
24+
withAuth: isDraftMode,
25+
})
2326

2427
if (!translatedPath) {
2528
throw new Error("Resource not found", { cause: "NotFound" })
@@ -34,6 +37,7 @@ async function getNode(slug: string[]) {
3437

3538
const resource = await drupal.getResource<DrupalNode>(type, uuid, {
3639
params,
40+
withAuth: isDraftMode,
3741
})
3842

3943
if (!resource) {

starters/basic-starter/app/[...slug]/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ async function getNode(slug: string[]) {
1212

1313
const params: JsonApiParams = {}
1414

15+
const isDraftMode = draftMode().isEnabled
1516
const draftData = getDraftData()
1617

1718
if (draftData.path === path) {
1819
params.resourceVersion = draftData.resourceVersion
1920
}
2021

2122
// Translating the path also allows us to discover the entity type.
22-
const translatedPath = await drupal.translatePath(path)
23+
const translatedPath = await drupal.translatePath(path, {
24+
withAuth: isDraftMode,
25+
})
2326

2427
if (!translatedPath) {
2528
throw new Error("Resource not found", { cause: "NotFound" })
@@ -34,6 +37,7 @@ async function getNode(slug: string[]) {
3437

3538
const resource = await drupal.getResource<DrupalNode>(type, uuid, {
3639
params,
40+
withAuth: isDraftMode,
3741
})
3842

3943
if (!resource) {

0 commit comments

Comments
 (0)