This is coming directly from here. That website is out of date, and so here it is, v2.0 fresh.
I am assuming you understand routes.
In your bootstrap.php file add the following. This will instantiate CakeSession (after it's inclusion), from there you can check the status of the login and define the routes based on whether the user is logged in or not.
and make sure this is in your routes.php file. Comment out or remove the old line.