diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-11-08 16:44:28 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-11-08 16:44:28 +0900 |
| commit | 8082931484f147189186974d0dfd7a45b8e9563b (patch) | |
| tree | 1b297613259a6e9fde11c871c62768e6972e26fc /backend/auth/session.go | |
| parent | 248c169c757fe9aeca0defc67cc8297e07a876d0 (diff) | |
| download | feedaka-8082931484f147189186974d0dfd7a45b8e9563b.tar.gz feedaka-8082931484f147189186974d0dfd7a45b8e9563b.tar.zst feedaka-8082931484f147189186974d0dfd7a45b8e9563b.zip | |
refactor(backend): Centralize environment variable loading in config.go
Diffstat (limited to 'backend/auth/session.go')
| -rw-r--r-- | backend/auth/session.go | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/backend/auth/session.go b/backend/auth/session.go index f480bff..eaf42e7 100644 --- a/backend/auth/session.go +++ b/backend/auth/session.go @@ -3,7 +3,6 @@ package auth import ( "errors" "net/http" - "os" "github.com/gorilla/sessions" "github.com/labstack/echo-contrib/session" @@ -18,22 +17,15 @@ const ( ) var ( - ErrNoSession = errors.New("no session found") - ErrNoUserIDInSession = errors.New("no user_id in session") - ErrNoSessionSecretEnvVar = errors.New("FEEDAKA_SESSION_SECRET environment variable is not set") + ErrNoSession = errors.New("no session found") + ErrNoUserIDInSession = errors.New("no user_id in session") ) type SessionConfig struct { store *sessions.CookieStore } -func NewSessionConfig() (*SessionConfig, error) { - secret := os.Getenv("FEEDAKA_SESSION_SECRET") - if secret == "" { - return nil, ErrNoSessionSecretEnvVar - } - useNonSecureCookie := os.Getenv("FEEDAKA_DEV_NON_SECURE_COOKIE") == "1" - +func NewSessionConfig(secret string, useNonSecureCookie bool) *SessionConfig { store := sessions.NewCookieStore([]byte(secret)) store.Options = &sessions.Options{ Path: "/", @@ -45,7 +37,7 @@ func NewSessionConfig() (*SessionConfig, error) { return &SessionConfig{ store: store, - }, nil + } } func (c *SessionConfig) GetStore() *sessions.CookieStore { |
