mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-06 00:01:40 +00:00
feat: add /users/me route
This commit is contained in:
31
apps/backend/internal/user/http.go
Normal file
31
apps/backend/internal/user/http.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/get-drexa/drexa/internal/reqctx"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type HTTPHandler struct {
|
||||
service *Service
|
||||
db *bun.DB
|
||||
authMiddleware fiber.Handler
|
||||
}
|
||||
|
||||
func NewHTTPHandler(service *Service, db *bun.DB, authMiddleware fiber.Handler) *HTTPHandler {
|
||||
return &HTTPHandler{service: service, db: db, authMiddleware: authMiddleware}
|
||||
}
|
||||
|
||||
func (h *HTTPHandler) RegisterRoutes(api fiber.Router) {
|
||||
user := api.Group("/users")
|
||||
user.Use(h.authMiddleware)
|
||||
user.Get("/me", h.getAuthenticatedUser)
|
||||
}
|
||||
|
||||
func (h *HTTPHandler) getAuthenticatedUser(c *fiber.Ctx) error {
|
||||
u := reqctx.AuthenticatedUser(c).(*User)
|
||||
if u == nil {
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
return c.JSON(u)
|
||||
}
|
||||
Reference in New Issue
Block a user