Below is sample Go code for two Google cloud functions. Each function is in a different project. I want to set a cookie in the first function (myfunction1), redirect to the second function (myfunction2), and access the cookie from that second function. I've tried a variety of parameters and values for setting the cookie but the second function always hits the error "Error getting mycookie: http: named cookie not present".
// Sample code for function https://us-central1-project1.cloudfunctions.net/myfunction1
myCookie := http.Cookie{
userCookie := http.Cookie{
Name: "mycookie",
Value: "foo",
Path: "/",
MaxAge: 60 * 60,
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteLaxMode,
Domain: ".cloudfunctions.net",
}
http.SetCookie(w, &myCookie)
url := "https://us-central1-project2.cloudfunctions.net/myfunction2"
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
// sample code for function https://us-central1-project2.cloudfunctions.net/myfunction2
cookie, err := r.Cookie("mycookie")
if err != nil {
log.Fatalf("Error getting mycookie: %v", err)
}
log.Println("cookie: ", cookie.Value)