WEBVTT 00:02.510 --> 00:07.580 So now that we can successfully log a user in on the front end, we, of course, need to log them out 00:07.580 --> 00:08.180 as well. 00:08.210 --> 00:10.480 So let's go to the roots for our front end. 00:10.490 --> 00:16.490 So in the far rootstock, out and down here in The Roots, I'll just create a new group called Logo 00:18.020 --> 00:21.570 and it's going to go to a handler that doesn't exist yet called logout. 00:22.700 --> 00:24.190 So let's go create that handler. 00:24.200 --> 00:26.090 So go over to our handler, Stocco. 00:26.720 --> 00:29.960 And at the very bottom, I'll just add another handler and it's dead. 00:29.960 --> 00:34.080 Simple folk with the receiver of app pointed to application. 00:34.820 --> 00:38.090 We'll just call it out and give it its two required parameters. 00:44.450 --> 00:49.790 And the first thing we'll do is call after a session and we want to destroy this session. 00:50.840 --> 00:59.150 And that takes one parameter, the context which we get from our our response, our request, and that 00:59.150 --> 01:00.030 destroys a session. 01:00.110 --> 01:05.360 And as I said a couple of lectures ago, any time you log in or log out, it's always a good idea to 01:05.360 --> 01:09.970 call after session, not renew token and give it the context as well. 01:11.360 --> 01:13.940 So that removes everything from our session. 01:14.780 --> 01:18.050 Now, the only other thing left to do here is redirect them somewhere. 01:18.470 --> 01:20.030 HTTP redirect. 01:22.100 --> 01:26.840 And we'll give it the W, the R, and we'll take them back to the login page, which is what people 01:26.840 --> 01:32.690 often expect to see once they log it, and the status will give his active status the other. 01:34.850 --> 01:37.070 OK, now one more change to make. 01:37.070 --> 01:44.380 And of course, that's in base layout HTML because when people actually click on this log outland, 01:44.540 --> 01:47.750 they're actually taken to a JavaScript function right here. 01:47.750 --> 01:48.330 Log out. 01:48.440 --> 01:49.900 And we don't want to do that anymore. 01:49.910 --> 01:52.120 We don't want to take them to log in. 01:52.190 --> 01:55.920 We want to just take them to log the route we just created. 01:56.270 --> 02:01.910 So when they click on log out, local storage from local storage will get rid of token and token expiry, 02:01.910 --> 02:02.780 which we're not using. 02:02.780 --> 02:08.270 But I put it in there anyway, and then we just redirect them to the log route, which is handled by 02:08.270 --> 02:14.320 our front end, destroys the session, renews the session token, and that redirects to the login page. 02:14.510 --> 02:15.640 So we should be able to run this. 02:16.400 --> 02:19.370 So if I start my application, I start. 02:23.990 --> 02:29.390 And go back to my Web browser and I'll go to the home page just to make sure everything's current, 02:29.720 --> 02:35.090 then I'll log in admin at example dot com, which I have to spell right. 02:35.420 --> 02:39.230 For example, dot com with a password, password and log in. 02:41.430 --> 02:42.480 Great, we're logged in. 02:42.600 --> 02:43.460 Now let's go. 02:44.920 --> 02:45.850 And I have an error. 02:45.910 --> 02:46.870 Let's see what the errors. 02:49.580 --> 02:50.720 Back in my roots. 02:53.970 --> 02:55.760 I love that as opposed to let's make that again. 02:55.920 --> 02:56.550 That was silly. 02:56.700 --> 03:01.890 OK, so we'll stop the application to start. 03:05.070 --> 03:11.300 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 03:11.310 --> 03:22.260 just go back a screen, reload everything, log in admin at example, dot com and the password. 03:22.440 --> 03:23.070 Password. 03:24.430 --> 03:24.710 And. 03:26.770 --> 03:29.830 And now I should be able a little longer, that looks better. 03:29.980 --> 03:33.840 OK, now there's one other change we want to make to the sessions. 03:33.850 --> 03:46.660 If you recall, if we go back to our main go file in our front end, which is under Wib mean when we 03:46.660 --> 03:49.960 initiate that session, which is way down here somewhere. 03:53.140 --> 03:58.330 We set up a very simple session, and by default, this uses cookies, and that's going to be really 03:58.330 --> 04:03.730 annoying as we go on through this course, simply because every time we start and stop our application, 04:04.090 --> 04:05.530 we lose all of our sessions. 04:06.100 --> 04:09.790 Now, that's not the case for our token because we're storing that in the database. 04:09.790 --> 04:16.420 So we'll just take advantage of the database store for the token package and implement that. 04:16.420 --> 04:20.620 And we'll store sessions in the database and I'll show you how to do that in the next lecture.