blob: e81d5b5f98c3148e923b3ab01ed249078c5326c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)
})
}
}
|