diff --git a/handlers/pages/dashboard.templ b/handlers/pages/dashboard.templ index b7d7f27..6e417fd 100644 --- a/handlers/pages/dashboard.templ +++ b/handlers/pages/dashboard.templ @@ -39,10 +39,8 @@ func (p *Dashboard) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Print(hasCookie, c) - if ck, err := cookies.Marshal(c); err != nil { + if err := cookies.MarshalToWriter(c, w); err != nil { rerrors.InternalError(err).ServeHTTP(w, r) - } else { - http.SetCookie(w, ck) } if err := p.Component().Render(r.Context(), w); err != nil { diff --git a/lib/cookies/cookies.go b/lib/cookies/cookies.go index 645046e..83661bb 100644 --- a/lib/cookies/cookies.go +++ b/lib/cookies/cookies.go @@ -39,6 +39,15 @@ func Marshal(v any) (*http.Cookie, error) { return c, err } +func MarshalToWriter(v any, w http.ResponseWriter) error { + if ck, err := Marshal(v); err != nil { + return err + } else { + http.SetCookie(w, ck) + } + return nil +} + func Unmarshal(c *http.Cookie, v any) error { if m, ok := v.(Unmarshaler); ok { return m.UnmarshalCookie(c)