HTTP Cookie won't get set

default discord avatar
TheFrontendlast year
8

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. πŸ‘€



@jmikrut 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
    last year

    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
    TheFrontendlast year

    Haha, oh no! Guess I was blind πŸ˜…

  • default discord avatar
    Sandro Wegmannlast year

    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
    last year

    ^^^^ 100%

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.