In this episode, we make our app's navigation aware of the user's authentication state. First, we look at how to grab details of the authenticated user using the auth functionality provided by Sentinel. We check out the user instance that's returned and realize we can tweak which model Sentinel uses for users, so we update the config to point to our own User model, making sure it extends the right Sentinel model for everything to work correctly.
Once that's sorted out, we update our User model to use proper mass-assignment protections (using $guarded instead of $fillable, just for simplicity). With all this in place, Sentinel now returns our custom User model when a user is authenticated.
Next, we want to make auth checks available inside our Twig templates. To do this, we register a new Twig helper that lets us use all the auth functionality in our views. We then add some logic to the navigation template to show or hide links like 'Dashboard', 'Register', and 'Login' based on whether a user is signed in. If the user is authenticated, we display their name too.
Finally, we test this all out by logging in and out, making sure the navigation updates as expected! We mention that access controls for routes (like middleware to protect pages) will come later. For now, your navigation is smart and user-aware!