What is the best practice to implement authentication/login screen?

Basically, what I want to do is before a page initializes (before it connects and pulls data from the database to be rendered), I want to know if the user is logged in (has the api token). If not logged in, show the login screen, then after successful login, reload the current route (be it home or a detail page).

Where should I put this “security check”? Is there a “before init” page event?