19 lines
452 B
Go
Raw Normal View History

2017-06-16 23:12:28 +00:00
package middleware
import "github.com/aerogo/aero"
2017-06-16 23:25:02 +00:00
// Session middleware saves an existing session if it has been modified.
2019-06-01 04:55:49 +00:00
func Session(next aero.Handler) aero.Handler {
return func(ctx aero.Context) error {
2017-06-16 23:12:28 +00:00
// Handle the request first
2019-06-01 04:55:49 +00:00
err := next(ctx)
2017-06-16 23:12:28 +00:00
// Update session if it has been modified
if ctx.HasSession() && ctx.Session().Modified() {
2019-06-01 04:55:49 +00:00
_ = ctx.App().Sessions.Store.Set(ctx.Session().ID(), ctx.Session())
2017-06-16 23:12:28 +00:00
}
2019-06-01 04:55:49 +00:00
return err
2017-06-16 23:12:28 +00:00
}
}