package api import ( "net/http" "strings" ) // DashboardAuth middleware validates the dashboard token. func DashboardAuth(token string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { auth := r.Header.Get("Authorization") if auth == "" { auth = r.URL.Query().Get("token") } auth = strings.TrimPrefix(auth, "Bearer ") if auth != token { http.Error(w, `{"error":"unauthorized"}`, http.StatusUnauthorized) return } next.ServeHTTP(w, r) }) } }