From 0e825a55e5e7a568441427307aa1acedbc387da4 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 17 Jan 2025 05:01:09 +0100 Subject: [PATCH] Fix bug not letting the first user have a session after user creation --- cmd/frontend/users.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/frontend/users.go b/cmd/frontend/users.go index 2565989..12a1faf 100644 --- a/cmd/frontend/users.go +++ b/cmd/frontend/users.go @@ -252,7 +252,7 @@ func UpdateSelf(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc { } } -func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc { +func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var err error user := &b.User{ @@ -305,8 +305,12 @@ func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc return } + session := newSession(w, c, sessionExpiryChan, user) + s[session.cookie.Value] = session + http.SetCookie(w, session.cookie) + data := new(struct{ Role int }) - data.Role = 0 + data.Role = user.Role tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {