diff --git a/docs/plans/2026-08-19-allow-signup-env.md b/docs/plans/2026-08-19-allow-signup-env.md index 8a72793..1238def 100644 --- a/docs/plans/2026-08-19-allow-signup-env.md +++ b/docs/plans/2026-08-19-allow-signup-env.md @@ -13,7 +13,7 @@ - Modify: `main.go` — read env var, set `AllowSignup` on the `AuthHandler`. - Modify: `handler/auth.go` — replace count-based gating with the `AllowSignup` flag. - No changes to `store/store.go` (`UserCount` is left in place). -- No changes to templates (the `HasUser` key drives the nav link already). +- Modify: `template/signin.html` — render the "Sign Up" nav link with `{{if .AllowSignup}}`. --- @@ -77,9 +77,19 @@ func (h *AuthHandler) allowSignup() bool { } ``` -- [ ] **Step 3: Update the three `HasUser` template renders to use `allowSignup()`** +- [ ] **Step 3: Update the three `AllowSignup` template renders to use `allowSignup()`** -Replace every occurrence of `"HasUser": h.hasUsers()` with `"HasUser": h.allowSignup()`. There are three (the initial GET render and the two error paths in the POST handler). +Replace every occurrence of `"AllowSignup": h.allowSignup()` where it was passed as the `HasUser` key. In the three render calls in the sign-in handler, ensure the map key is `AllowSignup`: + +```go +map[string]any{"AllowSignup": h.allowSignup()} +map[string]any{"Error": "Invalid email or password.", "AllowSignup": h.allowSignup()} +map[string]any{"Error": "Invalid email or password.", "AllowSignup": h.allowSignup()} +``` + +- [ ] **Step 3b: Update the sign-in template to use `AllowSignup` without inversion** + +In `template/signin.html`, the nav-link conditional must render the link when sign-up is allowed. Replace `{{if not .HasUser}}` with `{{if .AllowSignup}}`. (Retain the `{{end}}`.) - [ ] **Step 4: Commit** diff --git a/docs/specs/2026-08-19-allow-signup-env-design.md b/docs/specs/2026-08-19-allow-signup-env-design.md index bbe682f..5e54da9 100644 --- a/docs/specs/2026-08-19-allow-signup-env-design.md +++ b/docs/specs/2026-08-19-allow-signup-env-design.md @@ -41,7 +41,8 @@ truthy-value parser. Set the resulting boolean on the `AuthHandler`. `UserCount() > 0` check). - Replace the `hasUsers()` helper (driven by user count) with a check on `AllowSignup`, so the Sign In page shows/ hides the "Sign Up" nav link - based on whether sign-up is enabled. + based on whether sign-up is enabled. The sign-in template passes + `AllowSignup` and renders the link with `{{if .AllowSignup}}`. ### Unchanged diff --git a/handler/auth.go b/handler/auth.go index e9ca996..6822ac8 100644 --- a/handler/auth.go +++ b/handler/auth.go @@ -103,7 +103,7 @@ func (h *AuthHandler) allowSignup() bool { func (h *AuthHandler) ServeSignin(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { - h.Tpl.Render(w, "signin", map[string]any{"HasUser": h.allowSignup()}) + h.Tpl.Render(w, "signin", map[string]any{"AllowSignup": h.allowSignup()}) return } @@ -113,12 +113,12 @@ func (h *AuthHandler) ServeSignin(w http.ResponseWriter, r *http.Request) { user, err := h.Store.UserByEmail(email) if err != nil { - h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.allowSignup()}) + h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "AllowSignup": h.allowSignup()}) return } if err := bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)); err != nil { - h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.allowSignup()}) + h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "AllowSignup": h.allowSignup()}) return } diff --git a/template/signin.html b/template/signin.html index d17fa15..9ace01f 100644 --- a/template/signin.html +++ b/template/signin.html @@ -11,7 +11,7 @@