Get current user on frontend collection call

Hi everyone

I have been dealing with this great system for a few days now and have run into my first problem that I need help with.

I have extended the system with the “Public Auth” script with which I can log in users from the frontend without token. This works so far. Now I query a collection “Navigation” which returns the pages of a frontend navigation. This also works. But now I want to determine the authenticated user in my bootstrap in the webhook, who has triggered the call.

Here is what I have tried so far:

$app->on('collections.find.after.Navigation', function($name, &$entries) use ($app){

//$user = $app->module('cockpit')->getUser();
$user = $this->module('cockpit')->getUser();

if(!$user){
    $this->response->mime = 'json';
    $this->stop(403);
}

$token = $this->param('token', $this->request->server['HTTP_COCKPIT_TOKEN'] ?? $this->helper('utils')->getBearerToken());
if ($token && preg_match('/account-/', $token)) {

    echo $token;

    $account = $app->storage->findOne('cockpit/accounts', ['api_key' => $token]);

    print_r($account);

    if ($account) {
        //$allowed = true;
        //$this->module('cockpit')->setUser($account, false);
    }
}*/

//print_r($token);
//$check = $this->invoke('Cockpit\\Controller\\Accounts', 'account');
exit();
});

The “getUser()” call returns me an array with an empty _id and a set user group, in both tested variants. Via the token I get the correct access token, but then I don’t get the account back via “findOne(‘cockpit/accounts’”.

Now I am quite stumped and hope for a tip from you.

Thanks and greetings
Marcus

What I know user only can get via api ( maybe I’m wrong )

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://domain.com/api/cockpit/listUsers?token=XXXX");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$users = curl_exec($curl);
curl_close($curl);

      $json = json_decode($users);
      foreach ($json as $user) {
echo $user->email;
echo $user->id
      
      }