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)
|
||||
|
||||
Reference in New Issue
Block a user