From 7b07645ee204ee0340faa39c7a3e487d43dab30e Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 16 Feb 2026 16:50:10 -0500 Subject: [PATCH] feat(auth): show session expired message on login page - Update Login template to accept sessionExpired boolean parameter - Add conditional message box when session=expired query param present - Update /login route handler to parse session query param - Pass sessionExpired flag to Login template - Regenerate login_templ.go with new signature Displays friendly message: "Your session has expired. Please log in again to continue." when users are redirected due to expired sessions. --- internal/router/frontend.go | 3 ++- templates/login.templ | 12 ++++++++++-- templates/login_templ.go | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/router/frontend.go b/internal/router/frontend.go index c2c968f..abe949a 100644 --- a/internal/router/frontend.go +++ b/internal/router/frontend.go @@ -39,7 +39,8 @@ func registerFrontendRoutes(cfg *Config) { // Public routes for login and registration pages e.GET("/login", func(c echo.Context) error { var buf bytes.Buffer - err := templates.Login().Render(c.Request().Context(), &buf) + sessionExpired := c.QueryParam("session") == "expired" + err := templates.Login(sessionExpired).Render(c.Request().Context(), &buf) if err != nil { return err } diff --git a/templates/login.templ b/templates/login.templ index 77fc349..62873fd 100644 --- a/templates/login.templ +++ b/templates/login.templ @@ -1,6 +1,6 @@ package templates -templ Login() { +templ Login(sessionExpired bool) { @@ -29,7 +29,15 @@ templ Login() { - + + if sessionExpired { +
+

+ Your session has expired. Please log in again to continue. +

+
+ } +
diff --git a/templates/login_templ.go b/templates/login_templ.go index 38ef758..bbdc088 100644 --- a/templates/login_templ.go +++ b/templates/login_templ.go @@ -8,7 +8,7 @@ package templates import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -func Login() templ.Component { +func Login(sessionExpired bool) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -29,7 +29,17 @@ func Login() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Login

Login to Bookhoard

Don't have an account? Sign Up

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Login

Login to Bookhoard

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if sessionExpired { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

Your session has expired. Please log in again to continue.

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "

Don't have an account? Sign Up

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }