Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(basic-starter): fetch resource with auth in Draft Mode #775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/example-router-migration/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ async function getNode(slug: string[]) {

const params: JsonApiParams = {}

const isDraftMode = draftMode().isEnabled
const draftData = getDraftData()

if (draftData.path === path) {
params.resourceVersion = draftData.resourceVersion
}

// 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" })
Expand All @@ -34,6 +37,7 @@ async function getNode(slug: string[]) {

const resource = await drupal.getResource<DrupalNode>(type, uuid, {
params,
withAuth: isDraftMode,
})

if (!resource) {
Expand Down
6 changes: 5 additions & 1 deletion starters/basic-starter/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ async function getNode(slug: string[]) {

const params: JsonApiParams = {}

const isDraftMode = draftMode().isEnabled
const draftData = getDraftData()

if (draftData.path === path) {
params.resourceVersion = draftData.resourceVersion
}

// 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" })
Expand All @@ -34,6 +37,7 @@ async function getNode(slug: string[]) {

const resource = await drupal.getResource<DrupalNode>(type, uuid, {
params,
withAuth: isDraftMode,
})

if (!resource) {
Expand Down