From 8d80e9103f836284b73bc8d176c5ca63c31b0dfc Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 4 Mar 2024 00:32:16 +0100 Subject: Delay call of `view.New` after logging the user in There is no need to do extra work like creating a session and its associated view until the user has been properly identified and as many possibly-failing sql request have been successfully run. --- internal/ui/category_edit.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'internal/ui/category_edit.go') diff --git a/internal/ui/category_edit.go b/internal/ui/category_edit.go index fdc98b59..2edc8e13 100644 --- a/internal/ui/category_edit.go +++ b/internal/ui/category_edit.go @@ -14,9 +14,6 @@ import ( ) func (h *handler) showEditCategoryPage(w http.ResponseWriter, r *http.Request) { - sess := session.New(h.store, request.SessionID(r)) - view := view.New(h.tpl, r, sess) - user, err := h.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, r, err) @@ -43,6 +40,8 @@ func (h *handler) showEditCategoryPage(w http.ResponseWriter, r *http.Request) { categoryForm.HideGlobally = "checked" } + sess := session.New(h.store, request.SessionID(r)) + view := view.New(h.tpl, r, sess) view.Set("form", categoryForm) view.Set("category", category) view.Set("menu", "categories") -- cgit v1.2.3