forked from tangled.org/core
this repo has no description

appview/middleware: indiscriminately try to refresh the session

previously, we would only refresh sessions when authenticated requests
took place. the new middleware attempts a refresh for every request, if
expiry is approaching (<5m). this way, user sessions remain refreshing
by simply hanging out on tangled.

Signed-off-by: oppiliappan <me@oppi.li>

Changed files
+14
appview
middleware
state
+13
appview/middleware/middleware.go
···
type middlewareFunc func(http.Handler) http.Handler
func AuthMiddleware(a *oauth.OAuth) middlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
···
type middlewareFunc func(http.Handler) http.Handler
+
func (mw *Middleware) TryRefreshSession() middlewareFunc {
+
return func(next http.Handler) http.Handler {
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+
_, auth, err := mw.oauth.GetSession(r)
+
if err != nil {
+
log.Println("could not refresh session", "err", err, "auth", auth)
+
}
+
+
next.ServeHTTP(w, r)
+
})
+
}
+
}
+
func AuthMiddleware(a *oauth.OAuth) middlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+1
appview/state/router.go
···
s.pages,
)
router.Get("/favicon.svg", s.Favicon)
router.Get("/favicon.ico", s.Favicon)
···
s.pages,
)
+
router.Use(middleware.TryRefreshSession())
router.Get("/favicon.svg", s.Favicon)
router.Get("/favicon.ico", s.Favicon)