# Running into issues with basic auth

**URL:** <https://discourse.slimframework.com/t/running-into-issues-with-basic-auth/4440>\
**Category:** Questions\
**Created:** [October 8, 2020, 8:30pm UTC](https://discourse.slimframework.com/t/running-into-issues-with-basic-auth/4440 "2020-10-08T20:30:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunkoh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/dunkoh/32/995_2.png) [@dunkoh](https://discourse.slimframework.com/u/dunkoh)\
**Post date:** [October 8, 2020, 8:30pm UTC](https://discourse.slimframework.com/t/running-into-issues-with-basic-auth/4440/1 "2020-10-08T20:30:59Z")

</div>

Until today I had the group middleware basic auth being called like this:

```
->add(new Tuupola\Middleware\HttpBasicAuthentication([
"path" => "/api",
"realm" => "Protected",
"secure" => false,
"authenticator" => new ApiAuthenticator()

```

]));

But it was calling ApiAuthenticator for every file that came through the slim index (including css and js files) which we want to avoid to reduce unnecessary db calls.

I am attempting to set up the basic auth as an anonymous function to then pass into the group middleware, like this:

```
$basicAuth = function (Request $request, RequestHandler $handler) use ($app) {

return new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/api",
    "realm" => "Protected",
    "secure" => false,
    "authenticator" => new ApiAuthenticator()
]);

```

};

But I am running into issue - I have tried every which combination of request/response/handler that I could think of and completely at a loss.

The error I’m getting is:

```
TypeError: Return value of class@anonymous::handle() must be an instance of Psr\Http\Message\ResponseInterface, instance of Tuupola\Middleware\HttpBasicAuthentication returned in file /redacted-path/vendor/slim/slim/Slim/MiddlewareDispatcher.php on line 283
```

---

<div class="post-metadata">

**Author:** ![dunkoh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/dunkoh/32/995_2.png) [@dunkoh](https://discourse.slimframework.com/u/dunkoh)\
**Post date:** [October 14, 2020, 7:41pm UTC](https://discourse.slimframework.com/t/running-into-issues-with-basic-auth/4440/2 "2020-10-14T19:41:14Z")

</div>

we restructured some things and this is no longer an issue at this time. I can’t delete the post here.
