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

session Options is not working #143

Open
suyulin opened this issue Jul 18, 2017 · 10 comments
Open

session Options is not working #143

suyulin opened this issue Jul 18, 2017 · 10 comments

Comments

@suyulin
Copy link

suyulin commented Jul 18, 2017

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 ?
@mrichman
Copy link

mrichman commented Aug 8, 2017

Did you do session.Save() after session.Options() ?

@suyulin
Copy link
Author

suyulin commented Aug 9, 2017

yes,I found that the use of cookies alone, expiration time will not take effect, must be with the data can be, is this ?

@sshaplygin
Copy link

@suyulin May you send example source code?

@davidchandra95
Copy link

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 }

@pmadjidi
Copy link

I have the same problem as the above, has any one found a solution to the above problem?

@towelong
Copy link

I have the same problem too, it will lost cookie if I set maxAge.

@ollieparsley
Copy link

I'm experiencing this too. I'm on the latest versions (at time of writing) of gin, sessions and memcached sessions packages.

@hdlinh1808
Copy link

I have the same problem, please fix it.

@yukk001
Copy link

yukk001 commented Dec 18, 2023

I have the same problem, I saved a string session key, when I want to get it ,it is nil....

@yukk001
Copy link

yukk001 commented Dec 18, 2023

//启用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

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

9 participants