In the beginning check if the user is logged in with ```\OCP\JSON::checkLoggedIn()```.