sessions
sessions copied to clipboard
How to refresh the session
I test this frame , and found that the session can not refresh itself , which multple visit in 30 minutes , and the session can not renewal automatic.
How to resolve this problem ? thx
I hope someone answer to this issue cause I didn't find a solution on the web , I tried to implement the refresh on the middleware but way.
-
I tried a lot of tests, but the only one that works for me is to implement in the middleware a reset to the payload on the session and save it again .
-
Alright here is the the example of the middleware :
func CheckAuthMiddleware() gin.HandlerFunc { return func(c *gin.Context) { session := sessions.Default(c) userId := session.Get("id") phoneNum := session.Get("phone_number") if userId == nil || phoneNum == nil { c.Abort() c.Redirect(http.StatusMovedPermanently, "/auth/login") return } session.Set("id", userId) session.Save() c.Next() } }
I don't know if there is a better solution but this is the one that works . Thank you
you can refer to my project. link