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