Coder Social home page Coder Social logo

Comments (3)

SimYunSup avatar SimYunSup commented on July 28, 2024

It is related NextJS error related in vercel/next.js#60552, vercel/next.js#52209 . I think next/headers, next/cookies, next/cache... is not working properly in RSC with itself server API.

from payload.

jmikrut avatar jmikrut commented on July 28, 2024

Hey @sriechersrc — you should try and retrieve cookies with next/cookies. Does that work?

https://nextjs.org/docs/app/api-reference/functions/cookies

If there is indeed an issue, it seems to be an issue with Next.js though. We do indeed have access to cookies within Payload 3.x and our patterns work accordingly, so I will close this issue and we should track this on the above Next.js issues instead to de-duplicate.

One other note would be that if you are trying to authenticate, you can do that with payload.auth({ headers }). That might simplify things.

from payload.

sriechersrc avatar sriechersrc commented on July 28, 2024

Retrieving the cookies via next/cookies in an API Route seems also to be bugged. But I managed to move the logic to my main page component and dynamically enable draftMode like this:

  const isPreview = slugs[slugs.length - 1] === 'preview' // im redirecting to /my-path/preview so I am checking if "preview" exits on the slug

  const payload = await getPayload({
    config: configPromise,
  })

  if (isPreview) {
    const { headers } = await import('next/headers')

    const auth = await payload.auth({ headers: headers() })

    if (auth.user) {
      draftMode().enable()
      slugs.pop() // remove "preview" from the slugs
    } else {
      draftMode().disable()
    }
  }

from payload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.