19 lines
452 B
Go
Raw Normal View History

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