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)
- Sqlite3store error constraint failed: NOT NULL constraint failed: sessions.expiry (1299) HOT 4
- manage all session HOT 1
- Redis example is using a different Redis library HOT 8
- Custom names for sessions tables HOT 3
- support partitioned CHIPS cookies HOT 2
- pgxstore expects a *pgxpool.Pool instead of a *sql.DB HOT 5
- Flush / streaming HOT 2
- *scs.sessionResponseWriter does not implement http.Hijacker HOT 3
- Support Turso and libsql HOT 2
- Session getting added to DB, but not to cookie, when set to SameSiteNone, but works in SameSiteLax HOT 2
- Sign session ids/tokens HOT 5
- 2.7.0 breaks websocket compatibility HOT 2
- NATS Jetstream and session replication might be of interest HOT 3
- Submodules not being released with tags HOT 1
- Usage with TursoDB HOT 1
- sqlite3 store with custom table name
- Gob register custom struct HOT 2
- [interest check for new store] sqlite3 store using CGO-less modernc.org/sqlite
- [bug] Pop doesn't remove value if w.Write happened before sm.Pop HOT 2
- Database query built from user controller sources
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.