Open davidh16 opened 1 year ago
Hey @davidh16 , Alternatively you can also use gin to set and get cookie, works like a charm. Docs: https://gin-gonic.com/docs/examples/cookie/
Have you checked for error messages in the "cookie" tab of the network call in devtools?
i think it is because the cookie name contains invalid rune(maybe @).
I think you are developing locally and have a front-end back-end split, so it's easy to run into CORS problems. This is a typical CORS problem. go get github.com/gin-contrib/cors
middleware to let your back-end set up cross-domains. Remember that only by adding Allowcredials: True
, the browser allows you to extract data from the Set-Cookie request header.
so you search cors middeware doc.
config := cors.DefaultConfig()
config.AllowAllOrigins = []string{"http://localhost:3000"} // no set *
config.Allowcredials = True
router.Use(cors.New(config))
I am trying to set a cookie, but I am not getting it nor in Postman nor in browser.
I get a response message that I successfully logged in, but there is no cookie. To be clear this is just a part of a handler, the code before this snippet is not important since everything is working except setting the cookie.