Adekabang 8eaee0be8c refactor: update project references from Adekabang to khairul169
- Change Docker image references in docker-compose.yml and documentation
- Update Go module path and import statements in backend code
- Modify build script to reflect new image name
- Remove outdated copyright information from LICENSE file
2025-09-29 20:26:44 -04:00

28 lines
536 B
Go

package middleware
import (
"errors"
"khairul169/garage-webui/utils"
"net/http"
)
func AuthMiddleware(next http.Handler) http.Handler {
authData := utils.GetEnv("AUTH_USER_PASS", "")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
auth := utils.Session.Get(r, "authenticated")
if authData == "" {
next.ServeHTTP(w, r)
return
}
if auth == nil || !auth.(bool) {
utils.ResponseErrorStatus(w, errors.New("unauthorized"), http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}