So now that we can successfully log a user in on the front end, we, of course, need to log them out
as well.
So let's go to the roots for our front end.
So in the far rootstock, out and down here in The Roots, I'll just create a new group called Logo
and it's going to go to a handler that doesn't exist yet called logout.
So let's go create that handler.
So go over to our handler, Stocco.
And at the very bottom, I'll just add another handler and it's dead.
Simple folk with the receiver of app pointed to application.
We'll just call it out and give it its two required parameters.
And the first thing we'll do is call after a session and we want to destroy this session.
And that takes one parameter, the context which we get from our our response, our request, and that
destroys a session.
And as I said a couple of lectures ago, any time you log in or log out, it's always a good idea to
call after session, not renew token and give it the context as well.
So that removes everything from our session.
Now, the only other thing left to do here is redirect them somewhere.
HTTP redirect.
And we'll give it the W, the R, and we'll take them back to the login page, which is what people
often expect to see once they log it, and the status will give his active status the other.
OK, now one more change to make.
And of course, that's in base layout HTML because when people actually click on this log outland,
they're actually taken to a JavaScript function right here.
Log out.
And we don't want to do that anymore.
We don't want to take them to log in.
We want to just take them to log the route we just created.
So when they click on log out, local storage from local storage will get rid of token and token expiry,
which we're not using.
But I put it in there anyway, and then we just redirect them to the log route, which is handled by
our front end, destroys the session, renews the session token, and that redirects to the login page.
So we should be able to run this.
So if I start my application, I start.
And go back to my Web browser and I'll go to the home page just to make sure everything's current,
then I'll log in admin at example dot com, which I have to spell right.
For example, dot com with a password, password and log in.
Great, we're logged in.
Now let's go.
And I have an error.
Let's see what the errors.
Back in my roots.
I love that as opposed to let's make that again.
That was silly.
OK, so we'll stop the application to start.
We're not posting to log it, we're getting a get request to log out, so we'll go back here and I'll
just go back a screen, reload everything, log in admin at example, dot com and the password.
Password.
And.
And now I should be able a little longer, that looks better.
OK, now there's one other change we want to make to the sessions.
If you recall, if we go back to our main go file in our front end, which is under Wib mean when we
initiate that session, which is way down here somewhere.
We set up a very simple session, and by default, this uses cookies, and that's going to be really
annoying as we go on through this course, simply because every time we start and stop our application,
we lose all of our sessions.
Now, that's not the case for our token because we're storing that in the database.
So we'll just take advantage of the database store for the token package and implement that.
And we'll store sessions in the database and I'll show you how to do that in the next lecture.