feat: adjust route register
This commit is contained in:
@@ -11,37 +11,13 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) Auth(ctx fiber.Ctx) error {
|
||||
if ctx.Path() == "/v1/admin/auth" {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ctx.Path(), "/MP_verify_") {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ctx.Path(), "/v1/admin/") {
|
||||
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 != 1 {
|
||||
return ctx.Status(fiber.StatusForbidden).SendString("Forbidden")
|
||||
}
|
||||
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ctx.Path(), "/auth/") {
|
||||
return ctx.Next()
|
||||
}
|
||||
return ctx.Next()
|
||||
|
||||
fullUrl := string(ctx.Request().URI().FullURI())
|
||||
u, err := url.Parse(fullUrl)
|
||||
|
||||
28
backend/app/middlewares/mid_auth_admin.go
Normal file
28
backend/app/middlewares/mid_auth_admin.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user