Compare commits
2 Commits
9c143a43aa
...
6d735c20cb
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d735c20cb | |||
|
|
cb8a830345 |
@ -11,6 +11,7 @@ import (
|
|||||||
"apskel-pos-be/internal/service"
|
"apskel-pos-be/internal/service"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthMiddleware struct {
|
type AuthMiddleware struct {
|
||||||
@ -45,9 +46,13 @@ func (m *AuthMiddleware) RequireAuth() gin.HandlerFunc {
|
|||||||
setKeyInContext(c, appcontext.OrganizationIDKey, userResponse.OrganizationID.String())
|
setKeyInContext(c, appcontext.OrganizationIDKey, userResponse.OrganizationID.String())
|
||||||
setKeyInContext(c, appcontext.UserIDKey, userResponse.ID.String())
|
setKeyInContext(c, appcontext.UserIDKey, userResponse.ID.String())
|
||||||
|
|
||||||
if userResponse.Role != "superadmin" {
|
// Always override OutletID from token to prevent header injection.
|
||||||
setKeyInContext(c, appcontext.OutletIDKey, userResponse.OutletID.String())
|
// Set empty string if user has no outlet, so PopulateContext header value is ignored.
|
||||||
|
outletIDStr := ""
|
||||||
|
if userResponse.OutletID != nil && *userResponse.OutletID != uuid.Nil {
|
||||||
|
outletIDStr = userResponse.OutletID.String()
|
||||||
}
|
}
|
||||||
|
setKeyInContext(c, appcontext.OutletIDKey, outletIDStr)
|
||||||
|
|
||||||
logger.FromContext(c.Request.Context()).Infof("AuthMiddleware::RequireAuth -> User authenticated: %s", userResponse.Email)
|
logger.FromContext(c.Request.Context()).Infof("AuthMiddleware::RequireAuth -> User authenticated: %s", userResponse.Email)
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user