Passing authentication state to the frontend
We now have a complete mechanism for logging users in and out of Vuebnb. However, the frontend app is not yet aware of the user's authentication state. Let's remedy that now so we can add authentication-based features to the frontend.
auth meta property
We'll begin by adding the authentication state to the meta information we pass through in the head of each page. We'll utilize the Auth
facade check
method, which returns true
if the user is authenticated, and assign this to a new auth
property.
app/Http/Controllers/ListingController.php
:
... use Illuminate\Support\Facades\Auth; class ListingController extends Controller { ... private function add_meta_data($collection, $request) { return $collection->merge([ 'path' => $request->getPathInfo(), 'auth' => Auth::check() ]); } }
We'll also add an auth
property to our Vuex store. We'll mutate it from the addData
method which, as you'll recall from the previous chapter...