From 64b071b47a3a6421ba1e75e219f9877a8c8bb246 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Fri, 27 Dec 2024 05:23:43 -0500 Subject: [PATCH] Use a constant for the session key name We're using a 'magic string' for the echo session key name, which makes it easy for the different instances of the string to go out of sync. Using a named constant makes the intent clear and ensures all copies of the key name in the code stay in sync. --- api/session.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/session.go b/api/session.go index ca2a343..051139e 100644 --- a/api/session.go +++ b/api/session.go @@ -11,6 +11,8 @@ import ( type Session struct{} +const sessionKeyName = "fusion-client-session" + func (s Session) Create(c echo.Context) error { var req struct { Password string `json:"password" validate:"required"` @@ -24,7 +26,7 @@ func (s Session) Create(c echo.Context) error { return echo.NewHTTPError(http.StatusUnauthorized, "Wrong password") } - sess, _ := session.Get("login", c) + sess, _ := session.Get(sessionKeyName, c) if !conf.Conf.SecureCookie { sess.Options.Secure = false @@ -40,7 +42,7 @@ func (s Session) Create(c echo.Context) error { } func (s Session) Check(c echo.Context) (bool, error) { - sess, err := session.Get("login", c) + sess, err := session.Get(sessionKeyName, c) if err != nil { return false, err } @@ -52,7 +54,7 @@ func (s Session) Check(c echo.Context) (bool, error) { } func (s Session) Delete(c echo.Context) error { - sess, err := session.Get("login", c) + sess, err := session.Get(sessionKeyName, c) if err != nil { return err }