Effect CommunityEC
Effect Community9mo ago
21 replies
danielo515

Issue with Global Middleware Not Executing in Effect Platform

Hello everyone.
I've encountered an issue with global middleware in effect platform. I've implemented an auth middleware and attached it to the API globally. Just like this:
class ApiGlobalAuth extends HttpApi
  .make('GlobalAuth')
  .add(
    HttpApiGroup.make('test').add(
      HttpApiEndpoint.get('test', '/test').addSuccess(Schema.String),
    ),
  )
  .middleware(AuthMiddleware)
{}

const ApiGlobalAuthLive = HttpApiBuilder.api(ApiGlobalAuth).pipe(
  Layer.provide(
    HttpApiBuilder.group(ApiGlobalAuth, 'test', handlers =>
      handlers
        .handle('test', () => Effect.succeed('test'))),
  ),
  Layer.provide(AuthMiddlewareLive),
)

However the server doesn't seem to execute this middleware when endpoints are called.
The auth schema appears in the swagger documentation, so I assume it must be taken into account but in reality the auth middleware is not executed when I call the test ednpoint.
Is this the expected behavior? I can provide a repro if you think this is a bug
Was this page helpful?