Check for logged-in user from within router plugin

That code should actually work. However, if you want to call isLoggedIn() (why? not needed I think), then you should make sure you have a user object first:

if (($user = kirby()->user()) && $user->isLoggedIn()) {
  // do stuff
}