feat: add admin auth middleware
This commit is contained in:
@@ -16,6 +16,18 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ctx.Path(), "/v1/admin/") {
|
||||
token := ctx.Get("Authorization")
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user