Set session in POST methods, but cann't get session in GET methods
When I set a session in r.POST methods, but cann't get session in r.GET methods。
Are you correctly using session.Set(x, y) and session.Save() afterwards ?
hi,I have the same problem.
func (LoginController) Set(c *gin.Context) {
sessionToken,_ := uuid.NewV4()
//d6db0562-42c1-4bb2-b73e-988357fa0e6d
session := sessions.Default(c)
session.Set(sessionToken.String(),map[string]string{"name":"cai xu kun"})
_ = session.Save() //important
c.SetCookie("ginex_session",sessionToken.String(),0,"/","localhost",false,true)
}
func (LoginController) Get(c *gin.Context) {
sessionToken, _ := c.Cookie("ginex_session")
fmt.Println(sessionToken)
session := sessions.Default(c)
value := session.Get(sessionToken)
c.JSON(http.StatusOK,gin.H{"data":value})
}
Value is nil
I assumed the problem caused by input value type, this lib does handle that case well. Did you try this concept with a string value instead? @jwwb681232
@InterAI-CN Could you redo the POST operation vis curl, and paste HTTP Response Header in here? I think you forget session.Save()
@jwwb681232 What is c.Cookie("ginex_session")? Does you store sessionToken in there?
As soon as I decomposed my complex type into strings, it worked for me
i have the same problem, cannot get session