Authenticated checks if the request is authenticated
(tracer telemetry.Tracer)
| 19 | |
| 20 | // Authenticated checks if the request is authenticated |
| 21 | func Authenticated(tracer telemetry.Tracer) fiber.Handler { |
| 22 | return func(c fiber.Ctx) error { |
| 23 | _, span := tracer.StartFromFiberCtx(c, "middlewares.Authenticated") |
| 24 | defer span.End() |
| 25 | |
| 26 | if tokenUser, ok := c.Locals(ContextKeyAuthUserID).(entities.AuthContext); !ok || tokenUser.IsNoop() { |
| 27 | return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{ |
| 28 | "status": "error", |
| 29 | "message": "You are not authorized to carry out this request.", |
| 30 | "data": "Make sure your API key is set in the [x-api-key] header in the request", |
| 31 | }) |
| 32 | } |
| 33 | |
| 34 | return c.Next() |
| 35 | } |
| 36 | } |
nothing calls this directly
no test coverage detected