Files
cpone_dashboard/cpone-dashboard/menu/auth/middleware.go
2026-04-30 14:27:01 +07:00

17 lines
415 B
Go

package auth
import "net/http"
func Require(secret string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
username := getSession(r, secret)
if username == "" {
http.Redirect(w, r, basePath+"/mcu-login", http.StatusSeeOther)
return
}
next.ServeHTTP(w, setContext(r, username))
})
}
}