Merge pull request 'fix pointer' (#9) from feature/outlet-table into main
Reviewed-on: #9
This commit is contained in:
commit
6d735c20cb
@ -11,6 +11,7 @@ import (
|
||||
"apskel-pos-be/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AuthMiddleware struct {
|
||||
@ -45,9 +46,13 @@ func (m *AuthMiddleware) RequireAuth() gin.HandlerFunc {
|
||||
setKeyInContext(c, appcontext.OrganizationIDKey, userResponse.OrganizationID.String())
|
||||
setKeyInContext(c, appcontext.UserIDKey, userResponse.ID.String())
|
||||
|
||||
if userResponse.Role != "superadmin" {
|
||||
setKeyInContext(c, appcontext.OutletIDKey, userResponse.OutletID.String())
|
||||
// Always override OutletID from token to prevent header injection.
|
||||
// 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)
|
||||
c.Next()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user