In this episode, we look at how to fetch details about the authenticated user from any component in our application using the useSanctumAuth
composable. We start by showing how to import and use the isAuthenticated
property to determine if the user is logged in, and demonstrate how it switches between true
and false
as we sign in and out.
We also update the app navigation to dynamically display different links based on the user's authentication status—for example, showing "Sign In" and "Register" links when not logged in, and personalized user info when authenticated. We wrap up by briefly showing how to output the authenticated user's name, using the data returned by useSanctumAuth
, and tease improvements with TypeScript interfaces for later.
You’ll see how reactive this makes your navigation, and how easy it is to pull user information from anywhere in your app once you've set up this composable.