Comments (1)
Sorry for the (very) slow reply.
This is happening because the session cookie is never being written by the SCS middleware. I think the session cookie isn't being written because Echo's WrapMiddleware doesn't actually pass the underlying http.ResponseWriter onwards -- it replaces it entirely it's own c.Response() object instead and the session manager's Write method is therefore never called.
func WrapMiddleware(m func(http.Handler) http.Handler) MiddlewareFunc {
return func(next HandlerFunc) HandlerFunc {
return func(c Context) (err error) {
m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.SetRequest(r)
err = next(c)
})).ServeHTTP(c.Response(), c.Request())
return
}
}
}
Unless Echo can be changed so that WrapMiddleware extends the underlying http.ResponseWriter instead of replacing it, the only 'fix' I can see is to call session.Save manually in your handlers which modify the session data, like so:
func Index(ctx echo.Context) error {
data := make(map[string]interface{})
session.PutString(ctx.Request(), "sess", "ok")
_ = session.Save(c.Response(), c.Request())
data["sess"], _ = session.GetString(ctx.Request(), "sess")
return ctx.Render(200, "index.jet", data)
}
This essentially writes the session data and cookie, instead of relying on the middleware to do it.
from scs.
Related Issues (20)
- Refreshing sessions for mobile app use HOT 2
- Add Firestore support HOT 11
- Performance of Find() HOT 1
- Action on cookie create/update HOT 1
- panic in getSessionDataFromContext makes this package hard to work with HOT 8
- Can't find BuntDB store HOT 2
- Get all active sessions HOT 1
- Gin middleware HOT 3
- http.Flusher compatiability HOT 20
- With fiber HOT 4
- Let's go examples HOT 1
- constant panicing with chi v5 and pgxpool HOT 1
- Add a method to modify the deadline of the sessionData HOT 6
- NATs HOT 1
- Ignore GobCodec.Decode errors? HOT 3
- Possible to tag a new version? HOT 2
- Manually Set Token / Session ID? HOT 4
- Add example using gin
- Expose CtxStore interface to allow custom implementation HOT 1
- How to recover from corrupt session data? (or how to Destroy without loading the session) HOT 2
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 scs.