diff options
Diffstat (limited to 'app/middleware/require_user.go')
| -rw-r--r-- | app/middleware/require_user.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/middleware/require_user.go b/app/middleware/require_user.go new file mode 100644 index 0000000..e81d5b5 --- /dev/null +++ b/app/middleware/require_user.go @@ -0,0 +1,22 @@ +package middleware + +import ( + "net/http" + + "github.com/xlgmokha/x/pkg/x" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" +) + +func RequireUser(code int, url string) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + user := key.CurrentUser.From(r.Context()) + if x.IsZero(user) { + http.Redirect(w, r, url, code) + return + } + + next.ServeHTTP(w, r) + }) + } +} |
