Currently, there is golang api server and react client,
golang server = api.v1.localhost:8081
react client = localhost:3000
I try to log in, if successful, golang sets a cookie like the code below.
c.SetCookie(&http.Cookie{
Name: "refreshToken",
Value: *refreshToken,
Expires: *refreshTokenExpiresAt,
HttpOnly: true,
})
When you check cookies in your browser, they are saved as shown in the figure below. Checking the stored cookies, httponly is set to true, but the result is set to false, and the cookie disappears when I refresh the browser.
I think I'm doing it the wrong way, in setting the cookie, but I don't know the right way. How do I fix it, can I control cookies?
func Register() *echo.Echo {
e := echo.New()
e.GET("/swagger/*", echoSwagger.WrapHandler) // swagger 등록
validator.RegisterValidator(e) // 유효성검사 등록
e.Use(middleware.Cors()) // cors 등록
.........
func Cors() echo.MiddlewareFunc {
return middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{echo.GET, echo.POST, echo.DELETE, echo.PUT},
})
}
cors allowed this.