I implemented passport authentication in Laravel and the basic auth. I have UserController and inside it, I have the constructor methode:
public function __construct()
{
$this->middleware('auth.basic.once')->except(['index', 'show']);
$this->middleware('auth:api')->except(['index', 'show']);
}
The OnceBasic middleware:
public function handle($request, Closure $next)
{
if(Auth::guard('api')->check())
return $next($request);
else
return Auth::onceBasic() ?: $next($request);
}
In the OnceBasic middleware, I'm able to check if the user authenticated using the auth:api
then I prevent the authentication from trying to use the onceBasic
, So it worked correctly when using the access token. But it fails when trying to authenticate using the onceBasic(email, password) because the auth:api
trying to authenticate too and it fails(trying to call the redirectTo()
methods inside the default \App\Http\Middleware\Authenticate.php
)
My question is there a way to use both of these middlewares, to only successfully authenticate one and prevent the other from working?