2023-06-04 22:54:54 +08:00

34 lines
741 B
Go

package filter
import (
"ai-gateway/common/constant"
"ai-gateway/infrastructure/repository"
"ai-gateway/service"
"net/http"
"github.com/labstack/echo/v4"
)
var unauthorizedResp = map[string]interface{}{
"code": http.StatusUnauthorized,
"msg": "Login failed, please try again.",
}
// UserAuth 新版本
func UserAuth(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
fbc := repository.GetFbc(&c)
loginResult := service.Login.GetLoginResult(fbc, &c)
if loginResult == nil {
return c.JSON(http.StatusOK, unauthorizedResp)
}
//存入数据
c.Set(constant.CorpId, loginResult.CorpId)
c.Set(constant.BizId, loginResult.BizId)
c.Set(constant.UID, loginResult.Uid)
return next(c)
}
}