Add custom session

This commit is contained in:
2024-07-13 14:53:34 -04:00
parent 992ba29848
commit e0ebf2e6bb
4 changed files with 62 additions and 38 deletions

View File

@@ -0,0 +1,25 @@
package session
import (
"github.com/gorilla/sessions"
"os"
)
const (
MaxAge = 86400 * 30
IsProd = false
)
func New() sessions.Store {
key := os.Getenv("SESSION_SECRET")
if key == "" {
return nil
}
store := sessions.NewCookieStore([]byte(key))
store.MaxAge(MaxAge)
store.Options.Path = "/"
store.Options.HttpOnly = true
store.Options.Secure = IsProd
return store
}