extended MW
This commit is contained in:
parent
7ccf5eaa87
commit
520f0e6ec7
3 changed files with 37 additions and 18 deletions
|
|
@ -3,12 +3,25 @@ package router
|
|||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"merch-api/internal/user"
|
||||
"merch-api/pkg/responses"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func authMW() gin.HandlerFunc {
|
||||
func authMW(up user.Provider) gin.HandlerFunc {
|
||||
log.Debug("Auth Middleware enabled")
|
||||
return func(c *gin.Context) {
|
||||
c.Set("userUuid", "019caeab-aa81-7f09-a220-d7e675300638") //TODO placeholder for dev purposes
|
||||
userUuid := "019caeab-aa81-7f09-a220-d7e675300638" //TODO placeholder for dev purposes
|
||||
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)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue