This commit is contained in:
2025-12-20 11:05:35 +08:00
parent 788236ecc2
commit c42f2c651f
25 changed files with 245 additions and 95 deletions

View File

@@ -0,0 +1,34 @@
package middlewares
import (
"strings"
"github.com/gofiber/fiber/v3"
)
func (f *Middlewares) AuthAdmin(ctx fiber.Ctx) error {
if !strings.HasPrefix(ctx.Path(), "/v1/admin") {
return ctx.Next()
}
if ctx.Path() == "/v1/admin/auth" {
return ctx.Next()
}
token := ctx.Get("Authorization")
if token == "" {
token = ctx.Query("token")
if token == "" {
return ctx.Status(fiber.StatusUnauthorized).SendString("Unauthorized")
}
}
jwt, err := f.jwt.Parse(token)
if err != nil {
return ctx.Status(fiber.StatusUnauthorized).SendString("Unauthorized")
}
if jwt.UserID != -20140202 {
return ctx.Status(fiber.StatusForbidden).SendString("Forbidden")
}
return ctx.Next()
}