Git Product home page Git Product logo

Comments (10)

davidchandra95 avatar davidchandra95 commented on May 5, 2024 1

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 }

from contrib.

mrichman avatar mrichman commented on May 5, 2024

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

from contrib.

suyulin avatar suyulin commented on May 5, 2024

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

from contrib.

sshaplygin avatar sshaplygin commented on May 5, 2024

@suyulin May you send example source code?

from contrib.

pmadjidi avatar pmadjidi commented on May 5, 2024

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

from contrib.

towelong avatar towelong commented on May 5, 2024

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

from contrib.

ollieparsley avatar ollieparsley commented on May 5, 2024

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

from contrib.

hdlinh1808 avatar hdlinh1808 commented on May 5, 2024

I have the same problem, please fix it.

from contrib.

yukk001 avatar yukk001 commented on May 5, 2024

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

from contrib.

yukk001 avatar yukk001 commented on May 5, 2024
//启用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

from contrib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.