merch-api/pkg/router/middleware.go

29 lines
783 B
Go
Raw Normal View History

2026-02-23 19:33:21 +03:00
package router
2026-03-02 17:31:15 +03:00
2026-03-04 16:59:00 +03:00
import (
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
2026-03-06 19:07:14 +03:00
"merch-api/internal/user"
"merch-api/pkg/responses"
"net/http"
2026-03-04 16:59:00 +03:00
)
2026-03-02 17:31:15 +03:00
2026-03-06 19:07:14 +03:00
func authMW(up user.Provider) gin.HandlerFunc {
2026-03-04 16:59:00 +03:00
log.Debug("Auth Middleware enabled")
2026-03-02 17:31:15 +03:00
return func(c *gin.Context) {
2026-03-10 23:43:32 +03:00
//019caeab-aa81-7f09-a220-d7e675300638 //user_id 1
userUuid := "019cd29b-e35b-7eb2-85c6-111ca0d15bff" //TODO placeholder for dev purposes
2026-03-06 19:07:14 +03:00
log.Warnf("%v using placeholder uuid: %v", pkgLogHeader, userUuid)
userId, err := up.GetUserId(c, userUuid)
if err != nil {
c.JSON(http.StatusUnauthorized, responses.Unauthorized{Error: err.Error()})
log.WithError(err).Errorf("%v error converting user uuid to user id: %v", pkgLogHeader, userUuid)
return
}
c.Set("userId", userId)
2026-03-02 17:31:15 +03:00
c.Next()
}
}