sessions icon indicating copy to clipboard operation
sessions copied to clipboard

How to refresh the session

Open wujianworks opened this issue 1 year ago • 3 comments

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

wujianworks avatar Oct 05 '22 09:10 wujianworks

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.

Badr008 avatar Oct 18 '22 09:10 Badr008

  • 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

Badr008 avatar Oct 18 '22 10:10 Badr008

you can refer to my project. link

hhandhuan avatar Oct 23 '22 15:10 hhandhuan