You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
devops/routes/utils.go

20 lines
389 B

package routes
import (
"devops/entities"
"net/http"
"zestack.dev/slim"
)
func authSession(c slim.Context, next slim.HandlerFunc) error {
sess, err := store.Get(c.Request(), "session-key")
if err != nil {
return err
}
user, ok := sess.Values["user"].(*entities.User)
if !ok {
return c.Redirect(http.StatusMovedPermanently, "/login")
}
c.Set("user", user)
return next(c)
}