contrib
contrib copied to clipboard
session Options is not working
If i customize the options, like this
session := sessions.Default(c)
session.Options(sessions.Options{MaxAge: 60})
the cookie is lost
session := sessions.Default(c)
val := session.Get("user")
if val == nil ?
Did you do session.Save()
after session.Options()
?
yes,I found that the use of cookies alone, expiration time will not take effect, must be with the data can be, is this ?
@suyulin May you send example source code?
hi @mrfoe7 . it seems like i am facing the similar problem. This is the example code
func login(c *gin.Context) { // Save the username in the session session.Set(userkey, form.Username) // In real world usage you'd set this to the users ID session.Options(sessions.Options{MaxAge: 3600 * 12}) if err := session.Save(); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save session"}) return } }
and on the middleware
func AuthRequired(c *gin.Context) { session := sessions.Default(c) user := session.Get(userkey) log.Println("user", user) // return nil }
I have the same problem as the above, has any one found a solution to the above problem?
I have the same problem too, it will lost cookie if I set maxAge.
I'm experiencing this too. I'm on the latest versions (at time of writing) of gin, sessions and memcached sessions packages.
I have the same problem, please fix it.
I have the same problem, I saved a string session key, when I want to get it ,it is nil....
//启用session
//store := cookie.NewStore([]byte("xj_boot_golang"))
store := gormsessions.NewStore(global.GVA_DB, true, []byte("secret"))
//store := memstore.NewStore([]byte("xj_boot_golang"))
//store.Options(sessions.Options{MaxAge: 60 * 60 * 24})
Router.Use(sessions.Sessions("mysession", store))
// save session := sessions.Default(c)
session.Set(common.SESSION_ATTR_KEY, captchaId)
_ = session.Save()
//get session := sessions.Default(c) test := session.Get(common.SESSION_ATTR_KEY) test is nil