Перенести WithUser в httpx
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user