update authorized.go, database.go, middleware.go, project.go, response.go, role.go, service.go

This commit is contained in:
redtea committed 2024-10-20 12:00:00 +03:00
1 parent 53257427c9
commit b6133df436
7 files changed
+226

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
package handler
import (
"esproject/pkg/util"
"net/http"
"github.com/gin-gonic/gin"
)
const (
authorizationHeader = "Authorization"
userCtx = "UserInfo"
userHeader = "UserHeader"
)
func (h *Handler) userIdentity(c *gin.Context) {
header := c.GetHeader(authorizationHeader)
if header == "" {
util.NewErrorResponse(c, http.StatusUnauthorized, "empty auth header")
return
}
user, err := h.services.Authorization.Authorize(header)
if err != nil {
util.NewErrorResponse(c, http.StatusUnauthorized, err.Error())
}
c.Set(userCtx, user.Id)
c.Set(userHeader, header)
}