WEBVTT 00:01.800 --> 00:07.110 So as I suggested last time, we need to improve the way we're working with sessions right now, we're 00:07.110 --> 00:09.030 using a very simple session store. 00:09.060 --> 00:11.220 It's just cookies and there's nothing wrong with those. 00:11.220 --> 00:12.090 And they work fine. 00:12.300 --> 00:16.020 But in development particularly, it gets annoying pretty quickly. 00:16.230 --> 00:22.110 And I'll show you why, because it's not apparent to the user, to me as I'm working, that I've actually 00:22.110 --> 00:25.350 not logged out or logged out or things aren't exactly what I think they are. 00:25.380 --> 00:29.520 So I have my application running log in admin at example. 00:29.520 --> 00:31.050 Dot com password. 00:31.680 --> 00:32.280 Password. 00:35.440 --> 00:35.980 Great. 00:36.220 --> 00:42.940 So it appears that I'm logged in, but if I go back to my application, my idea and I open my terminal 00:42.970 --> 00:49.660 and I stop this application, I stop my front end sessions are gone and I'll start the application again. 00:50.400 --> 00:50.770 Start. 00:52.290 --> 00:58.680 And there it is, it's running when I go back to my Web browser and I click on, say, the products 00:58.680 --> 01:02.600 page by one widget, I still see logout up here. 01:02.610 --> 01:07.560 And that's because the way I'm determining whether or not that menu item shows log out instead of log 01:07.560 --> 01:12.380 in is based upon the presence of a token stored in local storage. 01:12.390 --> 01:15.550 But in fact, my front end off is entirely gone. 01:16.290 --> 01:21.840 So if I go to a virtual terminal, it takes me to the login screen and it still tells me that I'm logged 01:21.840 --> 01:23.720 in because it says log out up here. 01:24.000 --> 01:25.360 So that gets annoying in a hurry. 01:25.590 --> 01:29.880 So we're going to fix that and we're going to do that by using this package, which is an add on to 01:29.880 --> 01:38.160 the session manager we're using, and it's called Alex Edwards, slash X, slash my my MySQL store or 01:38.160 --> 01:39.030 my Seiple store. 01:39.110 --> 01:42.760 OK, so installing this is really simple. 01:42.780 --> 01:47.250 So the first thing I'll do is look at the documentation and right here it says setup. 01:47.250 --> 01:51.600 You should have a working MySQL database containing a sessions table and it shows me how to create it. 01:51.600 --> 01:55.580 So I'll copy this sequel and go back to my idea. 01:55.830 --> 01:59.130 And in my terminal I'll clear the screen and I'll type. 01:59.130 --> 02:07.500 So to generate and this time I'm going to generate a sequel, not Fears and I'll call it Create Sessions 02:08.310 --> 02:14.340 Table, and that creates two migrations up and down. 02:14.350 --> 02:20.940 So let's go to our migration's folder and I'll find the up migration, which is right here, and just 02:20.940 --> 02:21.990 paste that sequel in there. 02:22.770 --> 02:25.950 And the down migration is just to delete this session's table. 02:25.960 --> 02:32.660 So here in the down migration, I just type drop table sessions and save it. 02:33.570 --> 02:40.860 Now if I run this migration, so to migrate now I have a sessions table. 02:40.860 --> 02:42.180 So if I go look at my database 02:45.120 --> 02:49.380 and reload this, there is my first sessions table right there. 02:49.450 --> 02:50.790 OK, very simple. 02:50.790 --> 02:51.630 Three columns. 02:52.260 --> 02:53.210 So now how do we use this? 02:53.220 --> 02:54.810 Let's go back and look at the documentation. 02:56.310 --> 02:58.500 Obviously we need to import this. 02:58.500 --> 02:59.670 We need to go get this. 02:59.700 --> 03:01.040 So I'll, I'll copy this. 03:01.070 --> 03:08.490 GitHub, Dotcom's, Alex Edwards, so on and so forth, ending with MySQL store and go back to my Edem, 03:09.000 --> 03:15.810 clear my screen in my terminal and just type go get and then paste in that you URL. 03:17.800 --> 03:18.940 And that goes and gets it for me. 03:19.540 --> 03:24.790 So that means I need to go to my mango and where I'm creating the sessions right here. 03:26.500 --> 03:29.910 I just need to make a little change after line eighty six in my coat. 03:29.930 --> 03:31.510 So let's go back and see what that changes. 03:32.470 --> 03:39.160 The documentation says basically do this session manager store equals my ask. 03:39.160 --> 03:41.480 You will store new and hand at your database. 03:41.530 --> 03:42.460 Well can we do that. 03:42.470 --> 03:44.390 We have the database in the right spot. 03:45.910 --> 03:46.720 In fact, we do. 03:46.720 --> 03:48.130 We have it right here called Köln. 03:48.140 --> 03:53.050 So all I have to do and this is very simple configuration, but it's sufficient for our purposes right 03:53.050 --> 04:01.260 now is say session that store equals MySQL store and hopefully you will find it. 04:01.260 --> 04:04.660 It did dot new and had my database. 04:06.190 --> 04:11.740 Now when I stopped my application, like stop and make start. 04:13.900 --> 04:23.880 OK, and I will go back and look at my Web browser, go to the correct tab, refresh everything, OK, 04:23.890 --> 04:24.510 so it's running. 04:24.570 --> 04:28.110 Now let's look at the database table sessions and see what's in there. 04:28.120 --> 04:29.120 So I'll refresh this. 04:29.800 --> 04:30.640 There's nothing in there. 04:30.670 --> 04:38.650 Now let's log in admin app example, dot com with the password, password and log in. 04:41.110 --> 04:46.010 OK, we logged in and I can get to the virtual terminal, great, so let's go back to the home page. 04:46.480 --> 04:49.560 Let's look at the database table and see what's in there now. 04:50.740 --> 04:51.720 And now we have one entry. 04:51.790 --> 04:52.690 There's my token. 04:52.810 --> 04:55.030 OK, so let me go back to the. 04:56.620 --> 04:57.760 Stop the application. 05:00.090 --> 05:03.780 Make stop, OK, and now make a start again. 05:05.040 --> 05:07.980 Last time we did this, we lost our session, so it's running again. 05:08.760 --> 05:10.020 So I'm still logged in. 05:10.320 --> 05:16.890 And if I go to say the products page still says I'm logged in, but can I go to a virtual terminal where 05:16.890 --> 05:20.880 we're actually checking for the presence of that seminal variable user ID? 05:21.690 --> 05:26.880 And I can and that's going to make things ever so much easier as we progress through the remainder of 05:26.880 --> 05:27.480 this course. 05:27.990 --> 05:28.320 All right. 05:28.410 --> 05:29.000 Let's move on.