更新管理后台布局,优化菜单项标签,新增支付配置项。同时,调整API响应字段命名,确保一致性,提升代码可读性和维护性。
This commit is contained in:
25
soul-api/internal/middleware/admin_auth.go
Normal file
25
soul-api/internal/middleware/admin_auth.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AdminAuth 管理端鉴权:校验登录态(Cookie 或 Authorization),未登录返回 401
|
||||
// 开发模式(GIN_MODE=debug)下暂不校验,便于联调;生产请实现 Session/JWT
|
||||
func AdminAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if os.Getenv("GIN_MODE") == "debug" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
_, err := c.Cookie("admin_session")
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"success": false, "error": "未登录"})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user