Files
ai-agent/internal/middleware/chat_middleware.go
T
t 2bbf42b741 refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
2026-08-21 00:41:07 +08:00

26 lines
613 B
Go

package middleware
import (
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx"
"code.tczkiot.com/wlw/ai-agent/internal/services"
"github.com/gin-gonic/gin"
)
func ExternalUserMiddleware(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
if channel == nil {
ctx.JSON(200, httpx.JsonErrorMsg(ctx, "error.e0210"))
ctx.Abort()
return
}
external, err := services.SubjectService.CurrentExternal(ctx.Request.Context())
if err != nil {
ctx.JSON(200, httpx.JsonErrorMsg(ctx, "error.auth.expired"))
ctx.Abort()
return
}
httpx.SetExternalUser(ctx, external)
ctx.Next()
}