summaryrefslogtreecommitdiff
path: root/app/middleware/user.go
blob: 2865477a9670916165d8e823198bece5a596f854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package middleware

import (
	"net/http"

	"github.com/xlgmokha/x/pkg/mapper"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
)

func User() func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			next.ServeHTTP(w, r.WithContext(cfg.CurrentUser.With(
				r.Context(),
				mapper.MapFrom[http.Header, *domain.User](r.Header),
			)))
		})
	}
}