Have got first run working and publishing to Netlify
This commit is contained in:
parent
b7e0269e9d
commit
30d99eeb9e
22 changed files with 472 additions and 47 deletions
|
|
@ -7,7 +7,27 @@ import (
|
|||
"lmika.dev/lmika/weiro/services/auth"
|
||||
)
|
||||
|
||||
func AuthUser(auth *auth.Service) func(c fiber.Ctx) error {
|
||||
func OptionalUser(auth *auth.Service) func(c fiber.Ctx) error {
|
||||
return func(c fiber.Ctx) error {
|
||||
sess := session.FromContext(c)
|
||||
userID, _ := sess.Get("user_id").(int64)
|
||||
if userID == 0 {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
user, err := auth.GetUser(c.Context(), userID)
|
||||
if err != nil {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
c.Locals("user", user)
|
||||
c.SetContext(models.WithUser(c.Context(), user))
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func RequireUser(auth *auth.Service) func(c fiber.Ctx) error {
|
||||
return func(c fiber.Ctx) error {
|
||||
sess := session.FromContext(c)
|
||||
userID, _ := sess.Get("user_id").(int64)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue