How to make API action accessible only when logged in

How to make /app/api/getcustomerall accessible only by logged in users

My code

// API Action event

function Api_Action($app)
{
// All
$app->get('/getcustomerall', function ($request, $response, $args) {

        $responsemail = $response->withJson(ExecuteRows("SELECT email FROM users ORDER BY email ASC")); // Select the record by name and return as JSON

        return $responsemail ; // Return Psr\\Http\\Message\\ResponseInterface object

    });
}

Try with this

$app->get('/getcustomerall’, function ($request, $response, $args) {
	if (!isLoggedIn()) {
		return $response->write("Unauthorized Access")->withStatus(401);
	}
	$responsemail = $response->withJson(ExecuteRows("SELECT email FROM users ORDER BY email ASC"));
	return $responsemail;
})->add(new JwtMiddleware());