-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
35 lines (32 loc) · 830 Bytes
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package middleware
import (
"github.com/batudal/hyppo/config"
"github.com/batudal/hyppo/schema"
"github.com/gofiber/fiber/v2"
)
func Authorize(cfg config.Config) fiber.Handler {
return func(c *fiber.Ctx) error {
sess, err := cfg.Store.Get(c)
if err != nil {
return err
}
if sess.Get("user") == nil {
c.Append("HX-Retarget", "body")
c.Append("HX-Reswap", "beforeend")
return c.Render("modals/welcome", fiber.Map{})
}
c.Locals("user", sess.Get("user").(*schema.User))
return c.Next()
}
}
func AuthorizeMember(cfg config.Config) fiber.Handler {
return func(c *fiber.Ctx) error {
user := c.Locals("user").(*schema.User)
if !user.Membership {
c.Append("HX-Retarget", "body")
c.Append("HX-Reswap", "beforeend")
return c.Render("modals/membership", fiber.Map{})
}
return c.Next()
}
}