Update authMiddleware to redirect to main page if no password is set and user accesses login page

This commit is contained in:
Andy Oknen 2025-07-30 16:15:34 +00:00
parent 2b3b4c39d2
commit 428d29b176

View file

@ -201,8 +201,12 @@ func (w *WebUIServer) cleanupExpiredSessions() {
// authMiddleware checks for valid session or redirects to login // authMiddleware checks for valid session or redirects to login
func (w *WebUIServer) authMiddleware(next http.HandlerFunc) http.HandlerFunc { func (w *WebUIServer) authMiddleware(next http.HandlerFunc) http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) { return func(rw http.ResponseWriter, r *http.Request) {
// Skip authentication if no password is set // If no password is set and user tries to access login page, redirect to main page
if w.password == "" { if w.password == "" {
if r.URL.Path == "/login.html" {
http.Redirect(rw, r, "/", http.StatusSeeOther)
return
}
next(rw, r) next(rw, r)
return return
} }