sessions
sessions copied to clipboard
Session is not working after redirect
Session is working fine in the same handler, but when redirecting from route to other one, session is not working
also i used session in routing class like this
store := cookie.NewStore([]byte("secret"))
router.Use(sessions.Sessions("sessions", store))
Here is the controller code
func (controller *TestController) Register(c *gin.Context) {
var session = sessions.Default(c)
session.AddFlash(models.ErrorMsg{Field: "name", Message: "invalid input"}, "errors")
session.Save()
c.Redirect(http.StatusMovedPermanently, "/register")
return
}
func (controller *TestController) HandleRegister(c *gin.Context) {
var session = sessions.Default(c)
errors := session.Flashes("errors")
c.JSON(200, gin.H{
"errors": errors,
})
}
see #153
You can refer to my project https://github.com/hhandhuan/ku-bbs @ayman-elmalah
Any update for this issue? Does anybody know the final conclusion or workround?
What solved a similar issue for me was to handle errors in session.Save()
, unlike what is shown in the examples.
if err := session.Save(); err != nil {
log.Print("Error saving session: ", err)
}
Error saving session: securecookie: error - caused by: securecookie: error - caused by: gob: type not registered for interface: base.AuthResult
That indicates the thing I was trying to store on the session couldn't be serialized. It appears one solution includes using gob.Register
but I just pulled out the string I needed and it worked fine.