1
00:00:07,790 --> 00:00:11,320
Hey everybody what's going on this is Caleb with Debb slopes dot com.

2
00:00:11,350 --> 00:00:16,410
And in this video we're going to set our log in Visi to pop up when we need it to.

3
00:00:16,420 --> 00:00:21,760
We're going to also set it up so that we can actually authenticate users using firebase send them up

4
00:00:22,150 --> 00:00:25,360
and start adding users to our user base.

5
00:00:25,360 --> 00:00:26,700
Very very cool.

6
00:00:27,010 --> 00:00:29,710
Let's go ahead and pull up our X code project.

7
00:00:29,710 --> 00:00:30,690
Nice.

8
00:00:30,730 --> 00:00:31,300
Looks good.

9
00:00:31,300 --> 00:00:34,030
This is where we left off last time.

10
00:00:34,060 --> 00:00:37,080
And you know what I just realized.

11
00:00:37,120 --> 00:00:38,530
Let's look at this function here.

12
00:00:38,560 --> 00:00:42,800
It's giving us a warning saying user was defined but never used.

13
00:00:43,030 --> 00:00:48,310
I don't know that we really need to use this because if we get a user that's great if we get an error

14
00:00:48,340 --> 00:00:49,720
that's where this matters.

15
00:00:49,720 --> 00:00:51,250
So I'm actually going to change how this works.

16
00:00:51,250 --> 00:00:57,290
I just noticed that if error is not equal to nil.

17
00:00:57,310 --> 00:01:01,520
Let's go ahead and call log and complete and return.

18
00:01:01,520 --> 00:01:02,730
And let's get rid of this guard.

19
00:01:02,740 --> 00:01:04,400
We don't need that.

20
00:01:04,540 --> 00:01:07,280
Otherwise if there is no error we'll call log and complete.

21
00:01:07,300 --> 00:01:08,410
That's a much better way to do it.

22
00:01:08,410 --> 00:01:11,920
Let's go ahead and update it so that it looks like that.

23
00:01:12,040 --> 00:01:13,090
Very nice.

24
00:01:13,090 --> 00:01:16,180
And now we're going to go into main story storyboard.

25
00:01:16,240 --> 00:01:23,110
We're going to move this back to our tab bar controller here so that we can actually instantiate this

26
00:01:23,110 --> 00:01:24,730
from our app delegate.

27
00:01:24,970 --> 00:01:30,970
The delegate is going to allow us to actually present this view controller as soon as the authorization

28
00:01:30,970 --> 00:01:32,690
status changes.

29
00:01:32,740 --> 00:01:38,250
If the current user suddenly becomes nil meaning we've logged out it's going to present that automatically.

30
00:01:38,290 --> 00:01:40,010
Very very cool.

31
00:01:40,090 --> 00:01:46,630
Before we do that I want you just to remember this controller has a storyboard ID of author Visi that's

32
00:01:46,630 --> 00:01:48,890
going to be important in just a little bit.

33
00:01:48,910 --> 00:01:51,200
So let's go ahead and let's set this up.

34
00:01:51,340 --> 00:01:52,990
Go into your app delegate.

35
00:01:53,260 --> 00:01:59,080
And what we're going to do is right beneath where we configure our firebase app we're going to go ahead

36
00:01:59,110 --> 00:02:03,070
and we're going to just check to see if the current user is nil.

37
00:02:03,190 --> 00:02:10,770
So go ahead and type if off OTH current user is nil.

38
00:02:10,810 --> 00:02:14,290
OK this is what we're going to do if there is no user logged in.

39
00:02:14,290 --> 00:02:18,180
We're going to go ahead and present our log in visi.

40
00:02:18,280 --> 00:02:22,700
So to begin first we need to create a constant that's going to hold our storyboard.

41
00:02:22,700 --> 00:02:30,190
So go ahead and type let storyboard equals UI storyboard and if you give it some parentheses there you

42
00:02:30,190 --> 00:02:35,480
can give it a name right which the name is main storyboard right you can see that right there.

43
00:02:35,740 --> 00:02:38,490
And the bundle that it comes from is bundle.

44
00:02:38,500 --> 00:02:41,090
And we're going to use the main bundle.

45
00:02:41,160 --> 00:02:43,180
OK that's how you access the main storyboard.

46
00:02:43,180 --> 00:02:44,500
Very easy.

47
00:02:44,500 --> 00:02:51,110
Now we're going to actually go ahead and go beneath this and let's create an instance of Auth. AVC.

48
00:02:51,400 --> 00:02:58,660
So Type let off Visi and that's going to be equal to storyboard Dom instantiate view controller with

49
00:02:58,660 --> 00:02:59,420
identifier.

50
00:02:59,440 --> 00:03:06,800
This actually returns us a view controller and we can get the identifier by simply typing off Visi right.

51
00:03:06,850 --> 00:03:09,290
That's the ID we gave it in the storyboard.

52
00:03:09,310 --> 00:03:10,680
Very cool.

53
00:03:10,690 --> 00:03:16,360
Now in order to actually get this to present up on the screen when user is nil we're going to modify

54
00:03:16,360 --> 00:03:20,300
the window and we're going to set the window to be.

55
00:03:20,500 --> 00:03:25,060
We're going to call a function on it called Make key and visible and I'll show you what that is in just

56
00:03:25,060 --> 00:03:25,890
a second.

57
00:03:25,930 --> 00:03:30,050
First go ahead and type window make key and visible.

58
00:03:30,310 --> 00:03:33,230
And as soon as that's done you can look to see what it is.

59
00:03:33,280 --> 00:03:37,750
You can see it's a function but let's go ahead and let's see where it is called.

60
00:03:37,780 --> 00:03:43,450
Now it's a convenience function and it says most apps call this to show the main window and also make

61
00:03:43,450 --> 00:03:44,620
it key.

62
00:03:44,620 --> 00:03:45,220
Right.

63
00:03:45,250 --> 00:03:52,030
That means it's our our most important view controller it's the key view controller or the key window

64
00:03:52,030 --> 00:03:53,320
I mean.

65
00:03:53,320 --> 00:04:00,190
Now what we can access through the window is the route view controller K the route view controller is

66
00:04:00,190 --> 00:04:08,350
really important and it is basically going to allow us to call a view controller on top of the route

67
00:04:08,350 --> 00:04:13,630
view controller k we can present it on top meaning whatever view controller is currently shown we can

68
00:04:13,630 --> 00:04:15,850
present this on top from the delegate.

69
00:04:16,060 --> 00:04:24,550
So go ahead and type present view controller to present of course is Auth. VC and the animation is true

70
00:04:24,560 --> 00:04:28,820
we want it to pop up nicely and we don't care what it does when it's complete.

71
00:04:28,990 --> 00:04:29,360
OK.

72
00:04:29,380 --> 00:04:30,420
Very simple.

73
00:04:30,610 --> 00:04:35,830
But what this will do is it's going to check if the current user is Nele it's going to go ahead and

74
00:04:35,830 --> 00:04:37,500
instantiate off visi.

75
00:04:37,690 --> 00:04:44,440
It will make the window key and visible meaning it's visible and it's the key window meaning it's first

76
00:04:44,440 --> 00:04:46,990
and foremost and it can do a lot of cool stuff.

77
00:04:46,990 --> 00:04:53,000
Window root view controller we are accessing the view controller which is the currently presented one.

78
00:04:53,230 --> 00:04:59,380
We're going to present author Vicci on top of that so whether it is the Tabar controller whether it's

79
00:04:59,380 --> 00:05:02,260
the profile page the front page.

80
00:05:02,410 --> 00:05:06,970
If we are suddenly logged out it's going to present the authentication Visi which is really cool.

81
00:05:07,180 --> 00:05:10,020
I think we should go build and run to try it.

82
00:05:10,090 --> 00:05:14,260
I'm going to make sure I'm moved the initial view controller to the tab bar.

83
00:05:14,280 --> 00:05:15,340
Ok cool.

84
00:05:15,370 --> 00:05:16,290
So it's build and run.

85
00:05:16,300 --> 00:05:20,630
And let's go look at our simulator to see how we did.

86
00:05:21,280 --> 00:05:23,790
Let's see if it properly presents.

87
00:05:23,860 --> 00:05:25,230
Look at that beautiful.

88
00:05:25,260 --> 00:05:26,200
It worked.

89
00:05:26,230 --> 00:05:31,270
So we're not logged in but we have set it so that when no one is logged in we can pop it up there and

90
00:05:31,270 --> 00:05:33,010
it works beautifully.

91
00:05:33,010 --> 00:05:33,840
That's amazing.

92
00:05:34,030 --> 00:05:34,610
OK.

93
00:05:34,810 --> 00:05:35,580
Very cool.

94
00:05:35,590 --> 00:05:43,430
Let's go ahead and let's set up our log in the to be presented as soon as we tap on the e-mail button.

95
00:05:43,450 --> 00:05:45,850
So let's open up the assistant editor here.

96
00:05:46,030 --> 00:05:51,520
Let's select our view controller and we're going to get rid of this boilerplate junk and let's go ahead

97
00:05:51,580 --> 00:05:52,770
and begin.

98
00:05:52,780 --> 00:05:55,890
We need to actually create an outlet for this button.

99
00:05:55,900 --> 00:05:59,120
So go ahead and just drop it there.

100
00:05:59,320 --> 00:06:01,090
Right click and drag and drop.

101
00:06:01,270 --> 00:06:02,550
Then go to action.

102
00:06:02,620 --> 00:06:07,350
And we're going to call sign in with e-mail button was pressed.

103
00:06:07,360 --> 00:06:10,270
It's really long but it's definitely descriptive.

104
00:06:10,270 --> 00:06:14,980
And you know what we're not going to use these buttons yet but right click and drag and we'll just say

105
00:06:15,490 --> 00:06:25,880
for an action here Google sign in button was pressed and put another one here.

106
00:06:25,930 --> 00:06:28,180
Make sure it's in action.

107
00:06:28,180 --> 00:06:34,750
Facebook whoops Facebook sign button was pressed.

108
00:06:34,780 --> 00:06:35,070
All right.

109
00:06:35,070 --> 00:06:38,410
And we're not going to use those yet but just keep them there for now.

110
00:06:38,410 --> 00:06:44,350
Now what we do need to do is when the sign in with the e-mail button is pressed we need to set it so

111
00:06:44,350 --> 00:06:48,920
that our seinen or log in we see here is presented.

112
00:06:48,970 --> 00:06:55,050
So to do that all we need to do is create an instance of log NBC and then present it.

113
00:06:55,060 --> 00:07:01,100
So Type let log and visi equals storyboard.

114
00:07:02,010 --> 00:07:07,920
So I can't type storyboard dot instantiate view controller with identifier.

115
00:07:07,960 --> 00:07:16,090
Remember we just set it to be equal to the same thing as the class log in VC capital L log in VC.

116
00:07:16,150 --> 00:07:17,090
Very cool.

117
00:07:17,350 --> 00:07:24,760
And then we need to present it present log in VC animated and nyl for the completion because we don't

118
00:07:24,760 --> 00:07:29,290
care what happens when it's complete we just care that it is complete.

119
00:07:29,380 --> 00:07:30,020
OK.

120
00:07:30,310 --> 00:07:31,200
Very cool.

121
00:07:31,210 --> 00:07:37,060
It's going to ask that I force unwrap this because as you can see the storyboard here is being accessed

122
00:07:37,090 --> 00:07:38,100
operationally.

123
00:07:38,410 --> 00:07:42,920
So we're going to force and wrap but it's cool because we know that we have a value.

124
00:07:43,060 --> 00:07:44,650
We know that we have what we need.

125
00:07:44,650 --> 00:07:45,940
Very cool.

126
00:07:45,940 --> 00:07:53,050
And so as you know this should be all that we need to do to present the view controller we're accessing

127
00:07:53,050 --> 00:08:00,190
AVC we're getting an instance and we're presenting it using present view controller very very cool.

128
00:08:00,580 --> 00:08:02,280
That is pretty good.

129
00:08:02,380 --> 00:08:07,390
Let's go ahead and let's head into The View Controller class for log in visi.

130
00:08:07,700 --> 00:08:11,150
OK let's get rid of the boiler plate nonsense there.

131
00:08:11,150 --> 00:08:12,740
That looks good.

132
00:08:12,790 --> 00:08:18,540
And now what we need to do is we actually need to set up what happens to these text fields.

133
00:08:18,580 --> 00:08:24,040
And in order to modify them we're going to need to go ahead and create some Iby outlets to use those

134
00:08:24,040 --> 00:08:27,840
so the top is email field.

135
00:08:27,940 --> 00:08:32,760
OK right click and drag here to the bottom password field.

136
00:08:32,770 --> 00:08:34,120
Very cool.

137
00:08:34,120 --> 00:08:35,620
It looks great.

138
00:08:35,710 --> 00:08:36,940
And what else do we need.

139
00:08:36,940 --> 00:08:39,210
We need an action for our sign in button

140
00:08:42,400 --> 00:08:51,430
sign in button was pressed may leave some space there and our cancel button or maybe close button close

141
00:08:51,460 --> 00:08:54,790
button was pressed.

142
00:08:54,790 --> 00:08:55,260
Whoops.

143
00:08:55,260 --> 00:08:56,400
And that was an outlet.

144
00:08:56,410 --> 00:08:57,290
My bad.

145
00:08:57,310 --> 00:09:02,390
Delete that right click and delete the connection there.

146
00:09:02,620 --> 00:09:03,850
Let's do that one more time.

147
00:09:03,850 --> 00:09:04,800
The right way.

148
00:09:04,810 --> 00:09:06,230
Change it to an action.

149
00:09:06,610 --> 00:09:12,020
And we're going to type close button was pressed.

150
00:09:12,100 --> 00:09:12,610
Awesome.

151
00:09:12,610 --> 00:09:13,960
Create some room here.

152
00:09:14,120 --> 00:09:15,400
Now the close button.

153
00:09:15,460 --> 00:09:16,090
That's easy.

154
00:09:16,090 --> 00:09:17,880
We just need to call dismiss.

155
00:09:18,160 --> 00:09:20,920
Animated is true and completion is nil.

156
00:09:20,950 --> 00:09:22,990
OK that'll just get rid of the view controller.

157
00:09:22,990 --> 00:09:23,970
That's wonderful.

158
00:09:24,370 --> 00:09:31,810
But what we need to do now is we need to set up our registration button to actually register a user

159
00:09:31,810 --> 00:09:33,260
like it's supposed to.

160
00:09:33,310 --> 00:09:34,020
OK.

161
00:09:34,330 --> 00:09:42,190
Now in order to actually do that we need to set up the UI textfield delegate so that we can better monitor

162
00:09:42,190 --> 00:09:44,570
what is actually happening in these text fields.

163
00:09:44,620 --> 00:09:51,160
So to do that I'm going to go ahead and just create an extension of log in VC and I'm going to go ahead

164
00:09:51,190 --> 00:09:59,290
and conform to the UI textfield delegate and now that I've done that we can actually set the delegate

165
00:09:59,350 --> 00:10:01,930
of these two text fields in viewed ad lib.

166
00:10:01,960 --> 00:10:10,970
So let's do that by simply typing email field delegate equals self and password fields delegate equals

167
00:10:10,970 --> 00:10:12,050
self.

168
00:10:12,590 --> 00:10:17,390
Ok so now we can actually access these text fields we can call functions on them and do all kinds of

169
00:10:17,390 --> 00:10:18,750
really cool stuff.

170
00:10:18,800 --> 00:10:22,850
And so let's go ahead and let's just get rid of this for now.

171
00:10:22,880 --> 00:10:29,020
We don't need anything in here but we do need to set up what happens when we push that sign in button.

172
00:10:29,210 --> 00:10:35,480
So we're going to go ahead and set it up so that in order to sign in you have to put in an email and

173
00:10:35,480 --> 00:10:37,280
you have to put in a password.

174
00:10:37,310 --> 00:10:44,150
So let's go ahead and write some conditional code to check against that by typing if email field text

175
00:10:44,210 --> 00:10:54,170
is not equal to nil to nil and password field dot text is not equal to nil.

176
00:10:55,280 --> 00:11:02,110
OK so if there is text in both go ahead and we're just going to try to log in a user from our auth service.

177
00:11:02,150 --> 00:11:07,280
So go ahead and type off service instance log in user.

178
00:11:07,400 --> 00:11:08,960
We're going to always try that first.

179
00:11:08,990 --> 00:11:10,680
And this is getting really ugly.

180
00:11:10,880 --> 00:11:13,190
So I'm going to go ahead and open up.

181
00:11:13,430 --> 00:11:18,560
Log in Visi full screen because we've connected everything from the interface builder.

182
00:11:18,740 --> 00:11:23,980
So we're going to try to log any user first and if that fails then we will try to register them.

183
00:11:24,140 --> 00:11:25,100
OK.

184
00:11:25,100 --> 00:11:32,480
So go ahead and log in user go ahead and type email field text because if there is text in the e-mail

185
00:11:32,480 --> 00:11:33,840
field we'll pass it in.

186
00:11:34,180 --> 00:11:34,930
OK.

187
00:11:35,510 --> 00:11:39,000
The password is from the password field of course.

188
00:11:39,140 --> 00:11:44,810
And you know what it's going to complain to us that we're not unwrapping this because even though we

189
00:11:44,810 --> 00:11:49,010
know we have a value here it's still optional coming from the textfield.

190
00:11:49,370 --> 00:11:52,560
And so we have to unwrap it when we call this function.

191
00:11:52,640 --> 00:11:57,530
And now we're going to do is we're going to press enter on our completion handler and we're going to

192
00:11:57,530 --> 00:12:05,120
call this boolean success meaning if success then good if not success then bad and the error of course

193
00:12:05,150 --> 00:12:09,170
if we get an error back is just going to be log an error.

194
00:12:09,260 --> 00:12:14,030
Now let's say that we go through everything is successful we're good to go.

195
00:12:14,390 --> 00:12:20,980
If Success meaning if we are successful to log in we're going to go ahead and just dismiss the view

196
00:12:20,990 --> 00:12:23,180
controller because we don't need anything else.

197
00:12:23,180 --> 00:12:27,120
We don't need to display an error or we don't need to say anything that's good to go.

198
00:12:27,410 --> 00:12:30,040
But what if we have a problem.

199
00:12:30,080 --> 00:12:36,170
What if there is an error else meaning if success is not returned if we get false back we're going to

200
00:12:36,170 --> 00:12:38,980
go ahead and just print the error for now.

201
00:12:39,350 --> 00:12:40,170
Whoops.

202
00:12:41,320 --> 00:12:41,690
All right.

203
00:12:41,720 --> 00:12:41,950
Oops.

204
00:12:41,960 --> 00:12:45,090
No it's loggin air we said it to be log an error.

205
00:12:45,170 --> 00:12:47,050
Localized description.

206
00:12:47,420 --> 00:12:47,990
OK.

207
00:12:47,990 --> 00:12:48,670
Pretty cool.

208
00:12:48,680 --> 00:12:50,280
And I think it's going to warn us.

209
00:12:50,330 --> 00:12:51,280
Yeah you know what.

210
00:12:51,310 --> 00:12:56,850
In swift 4 you're not allowed to print things that are not explicitly strings.

211
00:12:56,870 --> 00:12:59,480
And so it's being coerced basically.

212
00:12:59,480 --> 00:13:07,340
So what we need to do actually is just type string and then describing log and air dot to localize description

213
00:13:07,360 --> 00:13:08,920
and that will get rid of that problem for us.

214
00:13:08,930 --> 00:13:13,950
As you can see we're basically just forcing this to be a string and not any.

215
00:13:14,330 --> 00:13:14,840
OK.

216
00:13:15,050 --> 00:13:20,960
So if success we're going to dismiss Otherwise we will print the error to the console so we can see

217
00:13:20,960 --> 00:13:22,430
what is the problem.

218
00:13:22,720 --> 00:13:28,400
And awesome So if success we're going to dismiss the view controller and that's awesome.

219
00:13:28,400 --> 00:13:33,320
Now what if we needed to register a user right.

220
00:13:33,320 --> 00:13:36,950
What if there was a problem and an error happened.

221
00:13:37,130 --> 00:13:44,230
We're going to go ahead and then call off service instance register a user.

222
00:13:44,490 --> 00:13:44,970
OK.

223
00:13:45,200 --> 00:13:50,960
Meaning if there is a success we're going to dismiss the view controller.

224
00:13:51,040 --> 00:13:56,620
Otherwise we're just going to print the error and then we're going to attempt to register the user because

225
00:13:57,340 --> 00:13:59,740
what if they have never logged in.

226
00:13:59,740 --> 00:14:03,000
Obviously there would be an error if they've never logged in.

227
00:14:03,040 --> 00:14:06,790
It will print the error and then move on to try to register this user.

228
00:14:06,790 --> 00:14:13,000
So now that we're inside of a closure we need to actually call self email field text to give it our

229
00:14:13,000 --> 00:14:19,980
e-mail self dot password field text and then user creation complete.

230
00:14:20,230 --> 00:14:21,300
We're going to do the same thing.

231
00:14:21,310 --> 00:14:25,230
We'll use success meaning if a user was successfully created.

232
00:14:25,420 --> 00:14:33,010
And if registration error is going to be the constant We'll name the error.

233
00:14:33,010 --> 00:14:37,700
So now oh it's yelling at us we need to unwrap these blah blah blah.

234
00:14:37,810 --> 00:14:38,480
Cool.

235
00:14:38,530 --> 00:14:39,010
OK.

236
00:14:39,100 --> 00:14:40,510
Now we're good.

237
00:14:40,570 --> 00:14:48,430
So what we're going to do is if we can successfully create a user if success go ahead and we're going

238
00:14:48,430 --> 00:14:50,350
to actually log in our user now.

239
00:14:50,350 --> 00:14:59,020
So go ahead and call off service for instance log in user self-caused email field dot text unwrap it

240
00:14:59,530 --> 00:15:06,040
self dot password field dot text unwrap it and then of course if log in is successful

241
00:15:08,830 --> 00:15:12,880
meaning Well you know what if we just create a user and they're created.

242
00:15:12,880 --> 00:15:16,110
If it's successful then we can't really get an error back from log in.

243
00:15:16,120 --> 00:15:20,470
So go ahead and just type nil because we can't get an airbag for that.

244
00:15:20,470 --> 00:15:23,440
And if it's successful we're going to go ahead and

245
00:15:25,990 --> 00:15:31,660
dismiss the view controller by calling it dismiss and animated is true.

246
00:15:31,870 --> 00:15:36,310
Completion is nil and this is how we're going to sign any user We're going to first try to log them

247
00:15:36,310 --> 00:15:36,780
in.

248
00:15:36,880 --> 00:15:42,430
If that fails we'll register them and after we've registered them successfully we will log in the user

249
00:15:43,180 --> 00:15:48,050
which is really cool although looks like we need to call self here because we're in a closure.

250
00:15:48,520 --> 00:15:53,000
But what if we didn't have a success what if it failed to register the user.

251
00:15:53,260 --> 00:15:58,620
In that case we'll just print a string describing.

252
00:15:58,810 --> 00:16:06,100
Let's go ahead and find that string describing there it is and it's going to be a registration error

253
00:16:06,190 --> 00:16:08,660
dot localized description.

254
00:16:09,160 --> 00:16:11,180
OK so we'll print that out if there's a problem.

255
00:16:11,470 --> 00:16:14,250
Very very cool sign in is now possible.

256
00:16:14,410 --> 00:16:16,650
And I think we should go give it a shot.

257
00:16:16,810 --> 00:16:21,670
When that sign in button is pressed it should try to log in the user it'll print out everything here

258
00:16:21,670 --> 00:16:28,510
to our console if it's successful it'll dismiss if it's unsuccessful it'll print the problem then try

259
00:16:28,510 --> 00:16:30,130
to register the user.

260
00:16:30,130 --> 00:16:35,070
If that's successful it will log in the user then dismiss them.

261
00:16:36,990 --> 00:16:42,150
Actually you know what we don't even need to have this secondary dismissal here we just need to go ahead

262
00:16:42,180 --> 00:16:45,150
and call the function.

263
00:16:45,180 --> 00:16:46,740
Let's go ahead and just type print

264
00:16:50,220 --> 00:16:59,070
successfully registered user because we are already dismissing the view controller if log in is successfully

265
00:16:59,070 --> 00:16:59,940
completed.

266
00:16:59,940 --> 00:17:05,940
So if it's a success we'll go ahead and just print successfully registered user because at this point

267
00:17:06,570 --> 00:17:12,450
if we register them with an email and password then we can't get an error back for registration.

268
00:17:12,550 --> 00:17:17,160
And of course connectivity issues is one thing but for the actual registration we can't get an error

269
00:17:17,160 --> 00:17:20,550
back so we'll just print successfully registered user.

270
00:17:20,550 --> 00:17:20,950
All right.

271
00:17:20,980 --> 00:17:27,700
So let's think about what we've done here we have set it up so that we can present our log in visi.

272
00:17:27,870 --> 00:17:33,960
Well we present off Visi from the app delegate then we present log in Visi when we tap the email button.

273
00:17:34,050 --> 00:17:34,910
OK.

274
00:17:35,160 --> 00:17:40,530
And then we can actually try to sign in so I'm going to pull open firebase here so we can watch our

275
00:17:40,530 --> 00:17:42,060
database reloaded.

276
00:17:42,060 --> 00:17:43,100
So it's good to go.

277
00:17:43,380 --> 00:17:48,870
Let's build and run this to our iPhone and let's see if it works let's try to add a user to firebase

278
00:17:48,870 --> 00:17:50,010
and see what happens.

279
00:17:52,290 --> 00:17:52,680
OK.

280
00:17:52,700 --> 00:17:57,050
So let's actually try to watch this side by side I'll pull this open on this side.

281
00:17:57,200 --> 00:18:01,080
You know what may be on this sites we can watch the console as well.

282
00:18:01,100 --> 00:18:07,970
Let's make this a bit smaller so we can see the console and firebase and this at the same time.

283
00:18:07,970 --> 00:18:08,840
All right.

284
00:18:08,840 --> 00:18:10,890
So click sign in by e-mail.

285
00:18:10,970 --> 00:18:12,560
It presents beautifully.

286
00:18:12,740 --> 00:18:13,630
Let's tap this.

287
00:18:13,640 --> 00:18:14,300
It dismisses.

288
00:18:14,300 --> 00:18:16,010
That's exactly what we want.

289
00:18:16,010 --> 00:18:22,780
Now let's go ahead and let's just type Caleb slopes dot com and let's just do.

290
00:18:23,150 --> 00:18:27,750
I am a wizard whip's.

291
00:18:27,950 --> 00:18:28,570
I am a wizard.

292
00:18:28,580 --> 00:18:29,330
That's my password.

293
00:18:29,330 --> 00:18:31,150
It's not our real password but just for this app.

294
00:18:31,160 --> 00:18:34,510
So when I type sign in it should first try to log any user.

295
00:18:34,580 --> 00:18:37,860
If that fails it should print an error try to register them.

296
00:18:37,970 --> 00:18:41,300
If that is successful it should log them in and then dismiss this view controller.

297
00:18:41,300 --> 00:18:48,310
Let's give it a shot tap sign in K and we will actually go ahead and see if we get any errors.

298
00:18:48,410 --> 00:18:53,420
The given sign and provider is disabled for this firebase project enable it in the firebase console

299
00:18:53,450 --> 00:18:56,270
under the seinen method tab of the auto section.

300
00:18:56,270 --> 00:18:58,730
I did not show you this yet and this is very important.

301
00:18:58,730 --> 00:19:02,590
You can't actually authenticate with anything unless you enable it in firebase.

302
00:19:02,600 --> 00:19:07,740
So go to firebase tap on authentication and check it out.

303
00:19:07,790 --> 00:19:09,810
There is a tab called Sign in method.

304
00:19:09,890 --> 00:19:11,060
Everything is disabled.

305
00:19:11,060 --> 00:19:13,390
We have not even given them the chance to log in.

306
00:19:13,390 --> 00:19:20,810
So let's turn on email off turn it on save it and now it's enabled Now the cool thing is we don't even

307
00:19:20,810 --> 00:19:22,220
need to build and run our app again.

308
00:19:22,220 --> 00:19:24,050
We can just tap sign in and see if it works.

309
00:19:24,050 --> 00:19:26,840
So let's go back to the database.

310
00:19:26,960 --> 00:19:30,960
Let's tap seinen says there is no user record.

311
00:19:31,180 --> 00:19:37,950
And then it tries to register them and it looks like it's not dismissing our view.

312
00:19:37,960 --> 00:19:39,150
Interesting.

313
00:19:39,190 --> 00:19:43,310
So I wonder why that is it looks like it successfully created the user.

314
00:19:43,330 --> 00:19:45,160
They popped up in our database.

315
00:19:45,160 --> 00:19:45,380
Right.

316
00:19:45,380 --> 00:19:46,880
There's our unique ID.

317
00:19:46,920 --> 00:19:52,360
There's the e-mail and the provider is firebase but it looks like it is not dismissing.

318
00:19:52,360 --> 00:19:53,470
That's interesting.

319
00:19:53,650 --> 00:19:54,200
And you know what.

320
00:19:54,220 --> 00:20:00,250
I think that is simply because when we log in the user it's not calling this function up here it's just

321
00:20:00,250 --> 00:20:01,740
we're calling it twice.

322
00:20:01,750 --> 00:20:06,750
So let's actually set it so that we can actually dismiss the view controller that was my bad.

323
00:20:06,760 --> 00:20:08,610
I was not thinking clearly there.

324
00:20:08,710 --> 00:20:15,760
So now when we actually try to log in and create a user it should dismiss I built and run ran built

325
00:20:15,760 --> 00:20:17,450
in RAM built and run.

326
00:20:17,840 --> 00:20:18,360
OK.

327
00:20:18,670 --> 00:20:23,410
Now it's not showing up and we need to think why is that why is it not popping up and why is it showing

328
00:20:23,410 --> 00:20:24,780
our Tabar controller.

329
00:20:24,790 --> 00:20:26,480
That's because we're authenticated.

330
00:20:26,620 --> 00:20:28,150
That's the coolest thing.

331
00:20:28,150 --> 00:20:34,510
So look if we go into our app delegate We said if there is a current user I mean if there is no current

332
00:20:34,510 --> 00:20:36,040
user we should present this.

333
00:20:36,040 --> 00:20:40,470
But right now we're log been so it's not presenting it that is the coolest thing.

334
00:20:40,480 --> 00:20:45,750
Now we'll set up later how to log out so that it pops up again but for now in order to get rid of ourselves

335
00:20:45,940 --> 00:20:50,580
we're going to just go ahead and delete the user's domain just like that.

336
00:20:50,590 --> 00:20:55,840
And when I go back in you'll see that it's it's still logged in because we need to actually delete the

337
00:20:55,840 --> 00:20:57,250
app.

338
00:20:57,250 --> 00:21:03,490
And now that our users are no longer in firebase if we delete it and then run it again it won't be logged

339
00:21:03,490 --> 00:21:05,550
in because we have basically remove the app.

340
00:21:05,560 --> 00:21:07,930
We've removed all of the things that get saved.

341
00:21:07,940 --> 00:21:13,420
And look it's still logged in so it looks like firebase is actually holding on to this user unless we

342
00:21:13,420 --> 00:21:14,880
explicitly sign them out.

343
00:21:14,890 --> 00:21:17,750
So we will handle that in a video to come.

344
00:21:17,770 --> 00:21:20,360
But for now we are successfully logging in.

345
00:21:20,500 --> 00:21:26,130
We're successfully adding users to our firebase database and in the next video we're going to set up

346
00:21:26,350 --> 00:21:32,080
a couple more of our view controllers and we're going to also set up our profile view controller and

347
00:21:32,080 --> 00:21:36,400
that's where we're going to be able to log out and actually forcefully sign ourselves out of firebase

348
00:21:36,790 --> 00:21:37,630
very very cool.

349
00:21:37,630 --> 00:21:38,670
Awesome job guys.

350
00:21:38,800 --> 00:21:40,600
And we'll see in the next video.
