summaryrefslogtreecommitdiff
path: root/app/middleware/require_user.go
blob: 8f54a04e25260561792cd3271548067fb47cb9ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package middleware

import (
	"net/http"
)

func RequireUser() func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if IsLoggedIn(r) {
				next.ServeHTTP(w, r)
			} else {
				http.Redirect(w, r, "/", http.StatusFound)
			}
		})
	}
}