Created
April 4, 2022 18:38
-
-
Save jsonw23/a5034916343b97280f605a0b0b315f7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package middleware | |
import ( | |
"github.com/gin-contrib/sessions" | |
"github.com/gin-contrib/sessions/cookie" | |
"github.com/gin-gonic/gin" | |
) | |
func Auth(r *gin.Engine) gin.HandlerFunc { | |
store := cookie.NewStore([]byte("secret")) | |
store.Options(sessions.Options{ | |
Secure: true, | |
HttpOnly: true, | |
}) | |
r.Use(sessions.Sessions("auth", store)) | |
return func(c *gin.Context) { | |
session := sessions.Default(c) | |
session.Set("test", "value") | |
session.Save() | |
c.Next() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment