aides-repo-api/internal/middlewares/auth.go
Maxim Slipenko e4f9743dea
Some checks failed
Format and Lint / format-check (push) Failing after 2s
Format and Lint / test (push) Successful in 52s
chore: change code.alt-gnome to code.aides.space
2025-01-07 17:54:16 +03:00

24 lines
651 B
Go

package middlewares
import (
"net/http"
"github.com/go-chi/render"
"code.aides.space/aides-infra/aides-repo-api/internal/common/errors"
"code.aides.space/aides-infra/aides-repo-api/internal/config"
)
func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Получаем значение из заголовка
token := r.Header.Get("Authorization")
if token != "Bearer "+cfg.Token {
render.Render(w, r, errors.ErrUnauthorized())
return
}
next.ServeHTTP(w, r)
})
}
}