-
Notifications
You must be signed in to change notification settings - Fork 170
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
Echo compatibility #57
Comments
Thanks Jaret! My main objectives for this were decoupling the modification and saving of session data, and making it easier for developers to communicate the session token to clients not using a cookie if they want to. There's still a bit of work to do, I still need to port some of the stores ( |
I have my code all tested. Unfortunately I could not interface the new (or old) I have a working version of an echo-enabled scs repository as a fork. I don't mind keeping the fork current with Thoughts? I don't want to create confusion with the fork but I also think it would be helpful to echo-users. I could write a GIST... or could rename the repo to (scs-echo) and have echo-users post issues there. |
Sorry for the delay on this. It's not obvious what to do about Echo. I'm pretty certain that the 'fault' (if there's such a thing) for the incompatibility issues lies with the design of Echo, not the design of SCS. SCS doesn't do anything unconventional, it works with the standard library, and I don't know of any other Go routers or frameworks where there is a compatibility problem. A couple of years ago I spent some time trying to figure out exactly what was causing the problems with Echo. IIRC, I filed an issue for one bug I found, but even when that was fixed the problems continued. I think it has all got something to do with the way that Echo manipulates the request If it is possible to create a fork of SCS which works with Echo, called |
Thanks for the discussion about this. I don't think there is currently any specific action that needs to be taken on the main SCS respository, so I'm going to close it for now. Feel free to reopen if necessary. |
Hi, just tested this package with echo Accessing session data works, writing session data works, renew token works and the cookie expiration gets updated. Here is a code example with redis: var SessionManager *scs.SessionManager
func Session() echo.MiddlewareFunc {
pool := &redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", viper.GetString(config.RedisHost))
},
MaxIdle: viper.GetInt(config.RedisMaxIdleConnections),
}
SessionManager = scs.New()
SessionManager.Store = redisstore.New(pool)
return echo.WrapMiddleware(SessionManager.LoadAndSave)
} Accessing and writing session data works like this (another middleware): func AuthMiddleware() echo.MiddlewareFunc {
return func(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
userId := SessionManager.GetString(c.Request().Context(), "userId")
// do some stuff
}
}
} To be honest, I didn't test it very well yet. |
@razorness Thanks, that's interesting. I've updated the note on Echo compatibility in the README to be less strongly-worded for now:
|
I also tried to get scs working with gin-gonic. Because of the implementation of |
I tried echo 4.2 with scs 2.4, error hander didn't work. Both default error handler and custom error handler returned 200 although http.StatusBadRequest was specified in ctx.JSON. When I commented out the middle ware usage with scs, it worked again. |
I am kind of locate the problem which'd be in the function The following snippet is the test function:
When I added the function to
The problem was gone. Therefore, if someone could investigate further, the reason might be found and got it solved. Thank you |
Well done @alexedwards on re-imagining scs. 🥇 This was a comprehensive rewrite. A number of items I appreciate:
Status
Status
IdleTimeout
andLifetime
were split from the oldoptions
.go.mod
added for go modules supportFor me, v2 solves a number of issues for which I had kept a permanent local fork of scs on my machine. (My fork was getting a bit dated too!)
I've done some testing and so far so good. I had one issue with a private
token
but this example provides a powerful solution to my issue.The text was updated successfully, but these errors were encountered: