Comments (10)
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.
Did you do session.Save()
after session.Options()
?
from contrib.
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.
@suyulin May you send example source code?
from contrib.
I have the same problem as the above, has any one found a solution to the above problem?
from contrib.
I have the same problem too, it will lost cookie if I set maxAge.
from contrib.
I'm experiencing this too. I'm on the latest versions (at time of writing) of gin, sessions and memcached sessions packages.
from contrib.
I have the same problem, please fix it.
from contrib.
I have the same problem, I saved a string session key, when I want to get it ,it is nil....
from contrib.
//启用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)
- [WIP] Move all middleware into separate repos on gin-contrib org HOT 8
- Package dependencies HOT 1
- Add the authorization middleware HOT 4
- Fix logrus import in ginrus (due to rename) HOT 3
- Add the rollbar middleware HOT 2
- Duration for a valid JWT token
- JWT force token expiration HOT 1
- commonlog
- [SOLVED] gin-contrib has gone? HOT 6
- `time` attribute duplicated in logrus/ginrus entry HOT 3
- auto update
- expir
- What is the license? HOT 1
- how to get x-response-time and write it in the http header with gin? HOT 2
- [QUESTION] sessions: Session `Get` method HOT 2
- Broken link in the "About" section HOT 1
- add support for samesite options HOT 1
- Remove repository with stolen source code
- the github page were 404 not found
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contrib.