Correctly handle errors from getSession

This commit is contained in:
2024-10-04 10:35:32 +02:00
parent 91d53a0f2a
commit c00645432b
6 changed files with 66 additions and 1 deletions

View File

@@ -67,7 +67,12 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return
}
} else {
session, _ := s.Get(r, "cookie")
session, err := getSession(w, r, c, s)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if auth, ok := session.Values["authenticated"].(bool); auth && ok {
files[1] = c.WebDir + "/templates/hub.html"
tmpl, err := template.ParseFiles(files...)
@@ -132,6 +137,8 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -155,6 +162,8 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}