feat: adjust route register

This commit is contained in:
yanghao05
2025-04-25 10:08:10 +08:00
parent 926b7f8d3b
commit 505c41e9ef
4 changed files with 34 additions and 27 deletions

View File

@@ -0,0 +1,28 @@
package middlewares
import (
"github.com/gofiber/fiber/v3"
)
func (f *Middlewares) AuthAdmin(ctx fiber.Ctx) error {
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()
}