Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to refresh the session #197

Open
wujianworks opened this issue Oct 5, 2022 · 3 comments
Open

How to refresh the session #197

wujianworks opened this issue Oct 5, 2022 · 3 comments

Comments

@wujianworks
Copy link

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

@Badr008
Copy link

Badr008 commented Oct 18, 2022

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
Copy link

Badr008 commented Oct 18, 2022

  • 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

@hhandhuan
Copy link

you can refer to my project. link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants