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 @@