reactjsgohttpcookieshttp-headers

Set-Cookies Header not setting the cookie


I'm building an app in Go and React.

I have my server built in Go, and I'm trying to send the auth cookie to the frontend.

When making a request from the frontend, it fails due to the cookie not existing, even though I can see Set-Cookie header in the response.

func SetTokenInCookies(w http.ResponseWriter, token string) {
    http.SetCookie(w, &http.Cookie{
        Name:     "authToken",
        Value:    token,
        Path:     "/",
        HttpOnly: true,
        Secure:   false,
        SameSite: http.SameSiteNoneMode,
    })
}

The cookie is not present in the dev tools on any browser I tried, nor is it accessible with document.cookie.

Set-Cookie header

I went over multiple threads on Stack Overflow that were similar to my issue, but none of those helped me.


Solution

  • So not sure what exactly fixed this, but I had to add credentials="include" to the http GET towards the server and also adjusted the cookie values for SameSite and Secure (as this is not allowed SameSite: http.SameSiteNoneMode and Secure: false) and it's finally working. Thank you Brits!