vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.25k stars 27.03k forks source link

DraftMode's isEnabled is not working #49256

Closed kb1995 closed 1 year ago

kb1995 commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 13.4.0
      eslint-config-next: 13.4.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

n\a

To Reproduce

This is my preview API route:

import { draftMode } from "next/headers";
import { redirect } from "next/navigation";

export async function GET(request) {
  const { searchParams } = new URL(request.url);
  const secret = searchParams.get("secret");
  const slug = searchParams.get("slug");

  // Check the secret and next parameters
  // This secret should only be known to this API route and the CMS
  if (secret !== process.env.STORYBLOK_TOKEN) {
    return new Response("Invalid token", { status: 401 });
  }

  // Enable Preview Mode by setting the cookies
  const location = `/${slug}`;

  draftMode().enable();
  console.log("---");
  console.log(draftMode().isEnabled);
  console.log("---");

  redirect(location);
}

In my terminal I get

---
false
---

Even when I query isEnabled by following the docs (https://nextjs.org/docs/app/api-reference/functions/draft-mode), it's still not working.

Describe the Bug

see above

Expected Behavior

Draft Mode to work

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

andrew-mcmaster commented 1 year ago

There is an open ticket for this earlier today here #49237

timneutkens commented 1 year ago

Duplicate of https://github.com/vercel/next.js/issues/49237

github-actions[bot] commented 1 year ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.