Перенести WithUser в httpx

This commit is contained in:
2026-10-06 14:49:19 +03:00
parent f42bf97b3a
commit 6720108793
6 changed files with 60 additions and 48 deletions
-18
View File
@@ -5,7 +5,6 @@ package auth
import (
"context"
"errors"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
@@ -46,20 +45,3 @@ func RequireUser(users UserLookup) gin.HandlerFunc {
c.Next()
}
}
// UserHandler is a handler that needs the identified caller.
type UserHandler func(c *gin.Context, actor uuid.UUID)
// WithUser adapts a UserHandler to gin. Reaching it without RequireUser in
// front is a wiring mistake, so it is reported as an internal error rather
// than blamed on the client with a 401.
func WithUser(h UserHandler) gin.HandlerFunc {
return func(c *gin.Context) {
actor, ok := httpx.UserID(c)
if !ok {
httpx.Error(c, errors.New("route is missing the RequireUser middleware"))
return
}
h(c, actor)
}
}