Files
vt/routers/user.go
2025-11-06 11:46:35 +01:00

33 lines
751 B
Go

package routers
import (
"git.kocoder.xyz/kocoded/vt/query"
"git.kocoder.xyz/kocoded/vt/utils"
"github.com/gofiber/fiber/v2"
)
type userRouter struct {
utils.Application
}
func RegisterUserRouter(group fiber.Router, appCtx utils.Application) {
router := &userRouter{Application: appCtx}
r := group.Use(utils.IsAuthenticated(appCtx))
r.Get("/current", router.getCurrentUserInfo)
}
func (r *userRouter) getCurrentUserInfo(c *fiber.Ctx) error {
u := query.User
session := c.Locals("USER_KEY").(*utils.Session)
currentUser, err := u.Where(u.ID.Eq(session.UserID)).First()
if err != nil {
r.Logger.Warn("Current mandant not found.", "error", err)
return c.SendStatus(fiber.StatusInternalServerError)
}
return c.JSON(currentUser)
}