This episode is for members only

Sign up to access "Authentication with Laravel Sanctum and Vue" right now.

Get started
Already a member? Sign in to continue
Playing
16. Logging out from the navigation

Transcript

00:00
It's going to be really annoying to have to keep clearing out our cookies every time we want to log out. So let's go ahead and implement the ability to log out directly from our navigation. Okay.
00:08
So if we head over to our navigation component, let's look for log out. We'll have a couple of these links. So we'll have one in the mobile navigation and one in the other navigation. And speaking of which, let's go and just make sure everything looks good here.
00:25
And you'll notice that with our mobile navigation, we still have both of these links in. So under the mobile nav section, just here, let's go down to the log out and log in links and just update these accordingly. So let's say V if authenticated, and here we'll say V if not authenticated.
00:46
So you can add any other link sheet in there that you need. Okay. So to log out, let's go ahead and say V on click. And we will of course call that log out method.
00:57
We'll do the same thing for the desktop version of this as well, or the larger viewport version of this. So V on click and log out. And if we just remind ourselves, we've got this log out link here.
01:10
But again, what we want to do is redirect the user once they are logged out. So we're going to create out a log out function directly in here, which calls this log out action. So we can alias that from within the import.
01:24
And then we're going to say log out action. And then once again, we're going to use our router to redirect. So let's import our router. And once we have logged out, let's say router push.
01:38
And where do we want to redirect to? Well, in this case, it can just be the homepage. Yeah, I said two. And of course that needs to be now.
01:46
Okay. Let's just try this out again by logging in. And we're logged in over on our dashboard. When we log out, we're redirected home.
21 episodes1 hr 35 mins

Overview

Learn how to authenticate with a Laravel API from Vue using the Composition API.

We'll start by setting up a fresh Laravel project with Sanctum and Fortify, configure everything step-by-step, and then implement the ability to authenticate from Vue with a simple auth module — thanks to the flexibility of the Composition API.

In the second half of the course, we’ll create our own beautiful starter kit with more features, including registration and middleware to protect routes.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!