How to get user in plugin route

using site()->user()->username() yields nothing a plugin route while being logged into panel. what am i missing? :cry:

$kirby->set('route',
	array(
		'pattern' => 'route/test.json',
		'action' => function($hash) {
			$json = ['username' => site()->user()->username()]; // will crash since null
			return response::json($json);
	    },
	    
	)
);

You are using a variable $hash, but it does not make sense because your are not using a placeholder? This is likely causing an error… site()->user()->username() is available, a just tested this in a Panel route with f::write()

1 Like

oh boy. time for a break;. thanks @texnixe for the quick response.

1 Like