Skip to content

Instantly share code, notes, and snippets.

@jsonw23
Created April 4, 2022 18:38
Show Gist options
  • Save jsonw23/a5034916343b97280f605a0b0b315f7e to your computer and use it in GitHub Desktop.
Save jsonw23/a5034916343b97280f605a0b0b315f7e to your computer and use it in GitHub Desktop.
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