Skip to content

Commit

Permalink
fix: Session cookie option
Browse files Browse the repository at this point in the history
  • Loading branch information
ken109 committed Nov 8, 2021
1 parent 4ea31c8 commit e1ec0ce
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions http/middleware/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ type SessionOption struct {

func Session(name []string, secret string, option *SessionOption) gin.HandlerFunc {
var (
corsSecure bool
corsSameSite http.SameSite
secure bool
sameSite http.SameSite
)

switch gin.Mode() {
case gin.ReleaseMode:
corsSecure = true
corsSameSite = http.SameSiteStrictMode
secure = true
sameSite = http.SameSiteStrictMode
case gin.TestMode:
secure = true
sameSite = http.SameSiteNoneMode
case gin.DebugMode:
corsSecure = false
corsSameSite = http.SameSiteLaxMode
secure = false
sameSite = http.SameSiteLaxMode
}

var maxAge = time.Hour * 24 * 365
Expand All @@ -39,9 +42,9 @@ func Session(name []string, secret string, option *SessionOption) gin.HandlerFun
sessions.Options{
Path: "/",
MaxAge: int(maxAge),
Secure: corsSecure,
Secure: secure,
HttpOnly: true,
SameSite: corsSameSite,
SameSite: sameSite,
},
)
return sessions.SessionsMany(name, store)
Expand Down

0 comments on commit e1ec0ce

Please sign in to comment.