Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

HTTP Cookie won't get set

default discord avatar
thefrontend2 years ago
4

Can someone send me a screenshot of a successful login request that sets an http only cookie? Right now I'm receiving the cookie but it won't get set in the browser and I'm a bit stuck. 👀



@364124941832159242

I just found out that for cross-site requests the cookie needs to be set "secure": "true" and "same-site": "none". That solved my issue. Would be good to have this option within the payload config to avoid patching the dependency. 🙌

  • discord user avatar
    jmikrut
    2 years ago

    these two options are indeed configurable in the payload config already 👍



    https://payloadcms.com/docs/authentication/config#options

    check out the

    cookies

    option



    you can set

    sameSite

    as well as

    secure

    right in the config, based on ENV vars or whatever you need 👍

  • default discord avatar
    thefrontend2 years ago

    Haha, oh no! Guess I was blind 😅

  • default discord avatar
    sandrowegmann2 years ago

    I wanted to follow up on this real quick, because I've wasted countless hours on those cookie issues during my years in web dev.



    If you are using axios or sth similar, you need to set withCredentials": true (or credentials: 'include' in node fetch ). NOT ONLY ON THE REQUEST USING THE AUTH COOKIE, BUT ALSO ON THE REQUEST WHERE YOU WANT TO RETRIEVE THE AUTH COOKIE (e.g. login request). Otherwise, you'll see the set-Cookie header in the response, but no cookie will be set
  • discord user avatar
    jmikrut
    2 years ago

    ^^^^ 100%

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.