I am trying to create a cookie in my client (127.0.0.1:3000) from an API made in Go (127.0.0.1:8080), I think I've added most headers in the response needed for CORS and the cookie has samesite=none and secure=true but it is still not being set. Below I've added a picture of the request and response as shown in the chrome devtools network tab and also code of axios where the request is made and code of go where the request is handled in the API server.
GO:
//Handles account sign ins
func Login(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Println("login handler")
//decoder := json.NewDecoder(r.Body)
//var t models.LoginUserData
//err := decoder.Decode(&t)
//if err != nil {
// log.Println(err)
//}
//middleware.SignIn(t.User.Username, t.User.Password)
http.SetCookie(w, &http.Cookie{Name: "sabor", Value: "merda", Path: "/", HttpOnly: false, SameSite: http.SameSiteNoneMode, Secure: true, Domain: "127.0.0.1"})
header := w.Header()
header.Set("Access-Control-Allow-Credentials", "true")
//header.Set("Access-Control-Expose-Headers", "Set-Cookie")
header.Set("Access-Control-Allow-Headers", "Content-Type, withCredentials")
header.Set("Access-Control-Allow-Origin", "http://127.0.0.1:3000")
header.Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
w.WriteHeader(http.StatusOK)
}
Axios:
let config = {
headers: {
withCredentials: true,
},
};
axios
.post(
"http://127.0.0.1:8080/login",
{
User: {
Username: username,
Password: password,
},
},
config
)
.then(function (response) {
console.log(response)
console.log(response.data)
console.log(response.headers)
console.log(response.data.cookie)
if (response.status === 200) {
console.log("if works")
}
})
.catch(function (error) {
console.log(error);
});
Request and Response image: Request and response image