From 3a25138d5b5552923f8c775125dc3d282f8b5b9b Mon Sep 17 00:00:00 2001 From: Othman Hendy Suseo Date: Sat, 20 Dec 2025 03:47:13 +0000 Subject: [PATCH] fix login form --- internal/httpapp/auth_middleware.go | 3 ++- internal/httpapp/handlers.go | 8 ++++++++ internal/httpapp/routes.go | 3 ++- web/templates/base.html | 2 +- web/templates/dashboard.html | 10 ++++++++++ web/templates/iscsi.html | 10 ++++++++++ web/templates/login.html | 2 +- web/templates/management.html | 10 ++++++++++ web/templates/protection.html | 10 ++++++++++ web/templates/shares.html | 10 ++++++++++ web/templates/storage.html | 10 ++++++++++ 11 files changed, 74 insertions(+), 4 deletions(-) diff --git a/internal/httpapp/auth_middleware.go b/internal/httpapp/auth_middleware.go index a18a498..76cb2ee 100644 --- a/internal/httpapp/auth_middleware.go +++ b/internal/httpapp/auth_middleware.go @@ -107,8 +107,9 @@ func (a *App) isPublicEndpoint(path, method string) bool { "/metrics", "/api/v1/auth/login", "/api/v1/auth/logout", - "/", // Dashboard + "/", // Root - redirects to login "/login", // Login page + "/dashboard", // Dashboard page (frontend will check token) "/storage", // Storage management page "/shares", // Shares page "/iscsi", // iSCSI page diff --git a/internal/httpapp/handlers.go b/internal/httpapp/handlers.go index 00e9a55..8e6d3e2 100644 --- a/internal/httpapp/handlers.go +++ b/internal/httpapp/handlers.go @@ -8,6 +8,14 @@ import ( ) func (a *App) handleDashboard(w http.ResponseWriter, r *http.Request) { + // Redirect to login page if not authenticated + // Since we use JWT in localStorage (client-side), we'll redirect to login + // and let the frontend handle token validation + http.Redirect(w, r, "/login", http.StatusFound) +} + +func (a *App) handleDashboardPage(w http.ResponseWriter, r *http.Request) { + // This is the actual dashboard page (accessed via /dashboard route) data := map[string]any{ "Title": "Dashboard", "Build": map[string]string{ diff --git a/internal/httpapp/routes.go b/internal/httpapp/routes.go index d62a2e0..e3bc212 100644 --- a/internal/httpapp/routes.go +++ b/internal/httpapp/routes.go @@ -12,7 +12,8 @@ func (a *App) routes() { a.mux.Handle("/static/", http.StripPrefix("/static/", fs)) // Web UI - a.mux.HandleFunc("/", a.handleDashboard) + a.mux.HandleFunc("/", a.handleDashboard) // Redirects to login + a.mux.HandleFunc("/dashboard", a.handleDashboardPage) // Actual dashboard page a.mux.HandleFunc("/login", a.handleLoginPage) a.mux.HandleFunc("/storage", a.handleStorage) a.mux.HandleFunc("/shares", a.handleShares) diff --git a/web/templates/base.html b/web/templates/base.html index 434108a..4ef98bb 100644 --- a/web/templates/base.html +++ b/web/templates/base.html @@ -30,7 +30,7 @@