I have a Go server deployed on heroku, and a react server deployed on Netlify, and I am running into an issue where the cookie set on sign in from heroku is not being set on my browser on the netlify. I have tried setting the domain of the cookie to netlify.app to millerbank.netlify.app (name of app), to omitting the domain, none of which worked at getting the cookie to reach the browser.
When I omit the Domain, I receive this error:
This Set-Cookie was blocked due to user preferences
When I change the Domain to netlify.app or millerbank.netlify.app, I receive this error:
This Set-Cookie was blocked because its Domain attribute is invalid with regards to the current host URL
Here is the code that sets the cookie on my Go server:
cookie := &http.Cookie{
Name: "jwt",
Path: "/",
HttpOnly: true,
Value: tokenString,
Expires: expiry,
Secure: true,
Domain: "netlify.app",
}
http.SetCookie(res, cookie)
Here are the CORS options:
newCors := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3000", "https://millerbank.netlify.app"},
AllowCredentials: true,
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
})
router.Use(newCors.Handler)
And here is the React code connecting to it:
try {
await axios.post("https://better-bank-account-api.herokuapp.com/api/v1/users/signin", data, { withCredentials: true })
dispatch({type: actionTypes.UPDATE_USERNAME, payload: username})
navigate("/dashboard")
} catch (error) {
console.log("err:", error.response.data);
if(error.response.data.errInvalidLogin){
setSigninError(error.response.data.errInvalidLogin)
setIsSigninError(true)
}
}
When running both my back end and front end on my localhost, cookies are set just fine, but making requests to my deployed back end from my deployed front end results in no cookies getting set. What other options do I have?