1 00:00:00,630 --> 00:00:06,120 Right, so here I am in the main view controller and I've just added a little bit of code here, which 2 00:00:06,120 --> 00:00:13,020 constitutes the function to log out, and I did that just to check the authentication, because I discovered 3 00:00:13,020 --> 00:00:18,900 that even if you delete the app and then you reloaded, I guess it has the same app identifier and device 4 00:00:18,900 --> 00:00:19,580 identifier. 5 00:00:19,950 --> 00:00:22,530 Therefore, Firebase just keeps it logged in. 6 00:00:22,890 --> 00:00:28,730 So, you know, that's quite a seamless user user experience, isn't it? 7 00:00:28,770 --> 00:00:33,120 You delete an app and then you come back and you've still got your login details and you're still logged 8 00:00:33,120 --> 00:00:34,320 in just pretty handy. 9 00:00:34,830 --> 00:00:41,580 So to log out what I did was this auth function or sign out, and that's to do with Firebase. 10 00:00:41,910 --> 00:00:43,460 This can give an error. 11 00:00:43,620 --> 00:00:47,130 So we have to put it in this special structure called a Dukat. 12 00:00:47,430 --> 00:00:49,550 And inside of there, we're going to try that. 13 00:00:49,830 --> 00:00:54,630 And what that means is if it throws an error, which it will if there is one, then we are going to 14 00:00:54,630 --> 00:00:57,560 catch that error here and we can do something accordingly. 15 00:00:57,930 --> 00:01:04,200 We don't actually have to do anything at this point because we're not letting the user we're not telling 16 00:01:04,200 --> 00:01:05,960 the user, not giving the user an option to log out. 17 00:01:05,990 --> 00:01:08,420 It's just for our own internal use at the moment. 18 00:01:09,510 --> 00:01:09,930 Right. 19 00:01:09,960 --> 00:01:15,600 So that's how they log out and that's how we get back to this point where we can see that the login 20 00:01:15,600 --> 00:01:19,670 screen and if we tap stuff, everything's too short, etc.. 21 00:01:21,150 --> 00:01:21,440 Right. 22 00:01:21,450 --> 00:01:22,320 So what are we going to do? 23 00:01:22,320 --> 00:01:28,530 We're going to go to auth view controller and we are going to look at the create user section. 24 00:01:28,530 --> 00:01:29,720 So we've created the user. 25 00:01:30,240 --> 00:01:33,780 And if the error is not equal to now, we're going to tell them what the error is. 26 00:01:34,110 --> 00:01:37,800 Otherwise, it's clear that the user has been created. 27 00:01:38,160 --> 00:01:44,790 So what we can do is call self-taught Dismas on The View controller and we'll have a nice animation 28 00:01:44,790 --> 00:01:45,450 to go with it. 29 00:01:45,780 --> 00:01:48,450 And on completion, we will do nothing. 30 00:01:48,960 --> 00:01:51,900 OK, so at this point we know we're logged in. 31 00:01:52,080 --> 00:01:56,810 We'll have a nice animation to log back to go to the previous screen. 32 00:01:57,300 --> 00:01:59,370 OK, we don't want the user to have to press back. 33 00:01:59,640 --> 00:02:01,740 We just want it to happen seamlessly. 34 00:02:04,280 --> 00:02:11,600 Right, so I'm going to put in another random email address and a random password, and then I'm going 35 00:02:11,600 --> 00:02:12,560 to click register. 36 00:02:13,960 --> 00:02:20,620 And we're in now, it's up to you if you want to show the user that they are logged in, that the registration 37 00:02:20,620 --> 00:02:27,310 was successful, sometimes it's I find it's not actually that necessary by mere virtue of the fact that 38 00:02:27,310 --> 00:02:33,040 they can access the screen where they can type messages, eventually, they will then know that they're 39 00:02:33,040 --> 00:02:33,570 logged in. 40 00:02:33,760 --> 00:02:39,540 So I think that part of the registration is pretty much done now. 41 00:02:39,670 --> 00:02:43,870 We need to look at the login section because we've created some users. 42 00:02:44,320 --> 00:02:46,720 We need to see how we log them in. 43 00:02:47,380 --> 00:02:50,020 So we want to get, again, our email and password. 44 00:02:50,650 --> 00:02:55,480 And I shouldn't be copying this, but I did it, so don't tell anyone. 45 00:02:57,430 --> 00:03:00,550 We can always get that from a different function if we wish later on. 46 00:03:01,960 --> 00:03:05,200 So let's look at how we lock in a user. 47 00:03:05,450 --> 00:03:07,060 Let's see if we have a login. 48 00:03:07,090 --> 00:03:08,170 No, we don't. 49 00:03:09,220 --> 00:03:10,750 Do we have a sign in? 50 00:03:10,930 --> 00:03:11,840 Yes, we do. 51 00:03:13,240 --> 00:03:14,650 So we want a sign in. 52 00:03:15,760 --> 00:03:20,670 That's an email with the email, link with email, password and completion. 53 00:03:20,710 --> 00:03:21,710 That's the one we want. 54 00:03:22,270 --> 00:03:26,070 So with email, of course, his email and password is the same. 55 00:03:26,830 --> 00:03:34,830 And then on completion, we should get some sort of result. 56 00:03:34,840 --> 00:03:35,830 What is that code? 57 00:03:36,160 --> 00:03:39,800 I assume it's going to be the same as the registration. 58 00:03:40,330 --> 00:03:41,350 Let's see if we get an error. 59 00:03:41,350 --> 00:03:43,330 And if we don't, that should be it. 60 00:03:44,690 --> 00:03:48,500 OK, so we're logged in, what do we want to do at that point we want to dismiss. 61 00:03:48,860 --> 00:03:54,260 So what I'm actually going to do is down here somewhere, I'm going to cut this code to dismiss the 62 00:03:54,260 --> 00:03:54,890 controller. 63 00:03:56,800 --> 00:04:04,080 And I'm just going to because dismisses a taken Keywood, we know what actually we can just have dismiss. 64 00:04:04,240 --> 00:04:07,470 We don't have to have self dismiss and we can just copy that. 65 00:04:07,780 --> 00:04:11,580 This one I don't mind copying because this hasn't changed since forever. 66 00:04:12,310 --> 00:04:14,320 So if we've signed in, then we're all good. 67 00:04:15,610 --> 00:04:21,010 Now it insists on having self, I should have known that, and it wants self because we're actually 68 00:04:21,010 --> 00:04:28,780 enclosed in this anonymous function and if we don't have self, we're going to have an error, as you 69 00:04:28,780 --> 00:04:29,430 can see. 70 00:04:30,790 --> 00:04:38,350 OK, what we do need is to also copy over this section to the login. 71 00:04:48,030 --> 00:04:53,760 So we're going to show an alert error and then just give the localized description, OK, so now if 72 00:04:53,760 --> 00:05:00,900 we run that, we should lock out the current user when it first loads and then we'll try to log in first 73 00:05:01,620 --> 00:05:04,100 with something that doesn't actually exist yet. 74 00:05:05,640 --> 00:05:13,920 So whatever at whatever dot com would be nice if I put an ad in there and then whatever password. 75 00:05:14,550 --> 00:05:19,180 So login, there's no need to record correspondence, identify the user may have been deleted. 76 00:05:19,560 --> 00:05:21,270 Wow, that's real friendly. 77 00:05:23,530 --> 00:05:30,750 OK, what if we register this user and I'm just going to give this a password of the word password and 78 00:05:30,750 --> 00:05:32,040 I'm going to copy that. 79 00:05:32,760 --> 00:05:35,130 It's going to register them and we're in. 80 00:05:35,190 --> 00:05:37,350 OK, now I'm going to run the app again. 81 00:05:37,740 --> 00:05:41,010 It's going to log that user out and ask them to login. 82 00:05:41,980 --> 00:05:43,740 So we're going to use that same user. 83 00:05:46,810 --> 00:05:47,290 Log-in. 84 00:05:48,630 --> 00:05:50,700 And there we go, we are in. 85 00:05:51,390 --> 00:05:54,870 OK, so that's pretty much the end of this little section. 86 00:05:55,110 --> 00:06:01,560 But I would say if you want to really snazzy up this and I think we will do this actually, because 87 00:06:01,890 --> 00:06:07,440 you should be pretty advanced now to the point where we actually want to build nice user interfaces 88 00:06:07,440 --> 00:06:08,040 for users. 89 00:06:08,400 --> 00:06:14,220 So what we're going to do in the next section is change the login and register buttons to be disabled 90 00:06:14,370 --> 00:06:16,740 or change them to a spinner or something like that. 91 00:06:16,950 --> 00:06:19,140 So the user can't access anything.