Files
webhooker/internal/handlers/index.go
clawbot 9a0a6f88e3
All checks were successful
check / check (push) Successful in 1m53s
feat: redirect root path based on auth state
/ now checks for an authenticated session:
- Authenticated users → 303 redirect to /sources
- Unauthenticated users → 303 redirect to /pages/login

Removes the old index page template rendering and formatUptime
helper (now dead code). Adds tests for both redirect cases.
2026-03-17 04:58:20 -07:00

21 lines
568 B
Go

package handlers
import (
"net/http"
)
// HandleIndex returns a handler for the root path that redirects based
// on authentication state: authenticated users go to /sources (the
// dashboard), unauthenticated users go to the login page.
func (s *Handlers) HandleIndex() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sess, err := s.session.Get(r)
if err == nil && s.session.IsAuthenticated(sess) {
http.Redirect(w, r, "/sources", http.StatusSeeOther)
return
}
http.Redirect(w, r, "/pages/login", http.StatusSeeOther)
}
}