From ce2efd9be7887dc79434841732891af5565e29a6 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Fri, 5 Jun 2026 11:24:05 +0000 Subject: [PATCH] feat: persistent session + logout button + auto-redirect for authenticated users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Logout button added to dashboard and event page headers - Landing page checks for valid session cookie → auto-redirects to dashboard - Session cookie persists 24h — closing and reopening browser keeps login --- internal/handlers/auth.go | 10 +++++++++- templates/dashboard.html | 2 ++ templates/event_expenses.html | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index 09c6151..844fe17 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -48,8 +48,16 @@ type AuthHandler struct { // LandingPage renders the landing page with the email input form for OTP login. // It parses templates/index.html and executes it with no template data. func (h *AuthHandler) LandingPage(w http.ResponseWriter, r *http.Request) { - tmpl := getTemplate("index.html") + // If the user already has a valid session, redirect to the dashboard. + if cookie, err := r.Cookie("session_token"); err == nil && cookie.Value != "" { + if _, ok := h.Sessions.Get(cookie.Value); ok { + w.Header().Set("HX-Redirect", "/dashboard") + w.WriteHeader(http.StatusOK) + return + } + } + tmpl := getTemplate("index.html") w.Header().Set("Content-Type", "text/html; charset=utf-8") if err := tmpl.Execute(w, nil); err != nil { log.Printf("ERROR [%s] handlers: LandingPage execute template: %v", time.Now().Format(time.RFC3339), err) diff --git a/templates/dashboard.html b/templates/dashboard.html index 6962f64..8e5d3f6 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -15,6 +15,8 @@

ReceiptNext

+
diff --git a/templates/event_expenses.html b/templates/event_expenses.html index 2b9f36f..b59b0c3 100644 --- a/templates/event_expenses.html +++ b/templates/event_expenses.html @@ -17,6 +17,8 @@ ← Events

{{.Event.Name}}

+