feat: add tenant admin invite management, ledger overview, order details, and order management features
- Implemented Invite management with creation, searching, and disabling functionalities. - Added Ledger overview for financial transactions with filtering options. - Developed Order Detail view for individual order insights and refund capabilities. - Created Orders management page with search, reset, and pagination features. - Enhanced user experience with toast notifications for actions and error handling.
This commit is contained in:
57
backend/app/middlewares/user.go
Normal file
57
backend/app/middlewares/user.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func shouldSkipUserJWTAuth(path string) bool {
|
||||
// 登录接口无需鉴权。
|
||||
if strings.Contains(path, "/v1/auth/login") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// UserAuth 为平台通用(非租户域)接口提供 JWT 校验,并写入 claims 到 ctx locals。
|
||||
func (f *Middlewares) UserAuth(c fiber.Ctx) error {
|
||||
if shouldSkipUserJWTAuth(c.Path()) {
|
||||
f.log.Debug("middlewares.user.auth.skipped")
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
authHeader := c.Get(jwt.HttpHeader)
|
||||
if authHeader == "" {
|
||||
f.log.Info("middlewares.user.auth.missing_token")
|
||||
return errorx.ErrTokenMissing
|
||||
}
|
||||
|
||||
claims, err := f.jwt.Parse(authHeader)
|
||||
if err != nil {
|
||||
f.log.WithError(err).Warn("middlewares.user.auth.invalid_token")
|
||||
switch err {
|
||||
case jwt.TokenExpired:
|
||||
return errorx.ErrTokenExpired
|
||||
case jwt.TokenMalformed, jwt.TokenNotValidYet, jwt.TokenInvalid:
|
||||
return errorx.ErrTokenInvalid
|
||||
default:
|
||||
return errorx.ErrTokenInvalid
|
||||
}
|
||||
}
|
||||
if claims.UserID == 0 {
|
||||
f.log.Warn("middlewares.user.auth.missing_user_id")
|
||||
return errorx.ErrTokenInvalid
|
||||
}
|
||||
|
||||
f.log.WithFields(map[string]any{
|
||||
"user_id": claims.UserID,
|
||||
}).Info("middlewares.user.auth.ok")
|
||||
|
||||
c.Locals(consts.CtxKeyClaims, claims)
|
||||
return c.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user