diff --git a/backend/internal/httpapi/middleware/auth.go b/backend/internal/httpapi/middleware/auth.go index 44e3f19..e3192da 100644 --- a/backend/internal/httpapi/middleware/auth.go +++ b/backend/internal/httpapi/middleware/auth.go @@ -9,8 +9,6 @@ import ( "high-loud-apps-labs/internal/httpapi/dto" ) -const CurrentUserKey = "current_user" - func Auth(users domain.UserRepository) gin.HandlerFunc { return func(c *gin.Context) { id := c.GetHeader("X-User-Id") @@ -30,15 +28,6 @@ func Auth(users domain.UserRepository) gin.HandlerFunc { } } -func CurrentUser(c *gin.Context) *domain.User { - if v, ok := c.Get(CurrentUserKey); ok { - if u, ok := v.(*domain.User); ok { - return u - } - } - return nil -} - func abortUnauthorized(c *gin.Context, msg string) { reqID := GetRequestID(c) body := dto.ErrorFromDomain( diff --git a/backend/internal/httpapi/middleware/context.go b/backend/internal/httpapi/middleware/context.go new file mode 100644 index 0000000..f467d36 --- /dev/null +++ b/backend/internal/httpapi/middleware/context.go @@ -0,0 +1,30 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" + + "high-loud-apps-labs/internal/domain" +) + +const ( + CurrentUserKey = "current_user" + CurrentTokenKey = "current_token" +) + +func CurrentUser(c *gin.Context) *domain.User { + if v, ok := c.Get(CurrentUserKey); ok { + if u, ok := v.(*domain.User); ok { + return u + } + } + return nil +} + +func CurrentToken(c *gin.Context) string { + if v, ok := c.Get(CurrentTokenKey); ok { + if s, ok := v.(string); ok { + return s + } + } + return "" +}