From d9ca3d5a6502cd536dc4d33a37571461b2b12135 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 29 Jan 2026 15:52:11 -0500 Subject: [PATCH] feat: add /bookshelf route and update redirects - Add /bookshelf route as default page for logged-in users - Update login and register handlers to redirect to /bookshelf - Update homepage to auto-redirect to /bookshelf when logged in - Preserve /dashboard route for backward compatibility - Update test redirects to use /bookshelf Changes: - main.go: Add /bookshelf protected route - auth.go: Change login/register redirects from /api/dashboard to /bookshelf (2 locations) - edge_cases_test.go: Update test redirect to /bookshelf - Maintains backward compatibility with existing /dashboard route This makes the beautiful bookshelf the default landing page for all authenticated users while keeping the old dashboard accessible. --- cmd/server/main.go | 24 +++++++++++++++++++++++- cmd/server/tests/edge_cases_test.go | 2 +- internal/handlers/auth.go | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 12e860b..e705a1a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -168,7 +168,29 @@ func main() { } }() - // Dashboard route (protected) + // Bookshelf route (protected) - new default for logged-in users + protected.GET("/bookshelf", func(c echo.Context) error { + userID := c.Get("user_id").(string) + userEmail := c.Get("user_email").(string) + userUsername := c.Get("user_username").(string) + userRole := c.Get("user_role").(string) + + user := templates.User{ + ID: userID, + Email: userEmail, + Username: userUsername, + Role: userRole, + } + + var buf bytes.Buffer + err := templates.BookShelf(user).Render(c.Request().Context(), &buf) + if err != nil { + return err + } + return c.HTML(http.StatusOK, buf.String()) + }) + + // Dashboard route (protected) - keep for backward compatibility protected.GET("/dashboard", func(c echo.Context) error { userID := c.Get("user_id").(string) userEmail := c.Get("user_email").(string) diff --git a/cmd/server/tests/edge_cases_test.go b/cmd/server/tests/edge_cases_test.go index 7c7b07f..f80545d 100644 --- a/cmd/server/tests/edge_cases_test.go +++ b/cmd/server/tests/edge_cases_test.go @@ -465,7 +465,7 @@ func TestHTMXRequests(t *testing.T) { w.Write([]byte(`
Registration successful! Redirecting...
`)) } else { json.NewEncoder(w).Encode(map[string]interface{}{ diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index 4f40ddd..5b07257 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -256,7 +256,7 @@ localStorage.setItem('token', '%s'); localStorage.setItem('refreshToken', '%s'); localStorage.setItem('user', JSON.stringify(%s)); document.cookie = 'token=%s; path=/; max-age=3600'; -window.location.href = '/api/dashboard'; +window.location.href = '/bookshelf'; `, accessToken, refreshToken, fmt.Sprintf(`{"id":"%s","email":"%s","username":"%s"}`, uuid.UUID(user.ID.Bytes).String(), user.Email, user.Username), accessToken) return c.HTML(http.StatusCreated, html) } @@ -412,7 +412,7 @@ localStorage.setItem('token', '%s'); localStorage.setItem('refreshToken', '%s'); localStorage.setItem('user', JSON.stringify(%s)); document.cookie = 'token=%s; path=/; max-age=3600'; -window.location.href = '/api/dashboard'; +window.location.href = '/bookshelf'; `, accessToken, refreshToken, fmt.Sprintf(`{"id":"%s","email":"%s","username":"%s","first_name":"%s","last_name":"%s"}`, uuid.UUID(user.ID.Bytes).String(), user.Email, user.Username, user.FirstName.String, user.LastName.String), accessToken) return c.HTML(http.StatusOK, html) }