1
00:00:00,210 --> 00:00:00,900
Welcome back.

2
00:00:01,110 --> 00:00:07,890
And this week we are going to sign in the user using email and password and therefore you can go ahead

3
00:00:07,890 --> 00:00:09,010
and try to do yourself.

4
00:00:09,030 --> 00:00:14,070
So just follow along the password authentication here in the firebase documentation.

5
00:00:14,370 --> 00:00:17,180
And you can see that it's, um.

6
00:00:17,580 --> 00:00:25,320
Yeah, they're using an extra variable here, which is called off in order to have the firebase of system

7
00:00:25,320 --> 00:00:30,570
once and not having to recreate it every single time you want to do something with it.

8
00:00:30,720 --> 00:00:37,050
But as we are just using it once when signing in, it's actually find a way we do it, but both ways

9
00:00:37,050 --> 00:00:37,390
are fine.

10
00:00:37,410 --> 00:00:44,010
So you can, of course, go ahead and create a late initialized variable called Firebase all or just

11
00:00:44,010 --> 00:00:45,560
all, and then use that.

12
00:00:45,840 --> 00:00:48,030
So you need to initialize it.

13
00:00:48,030 --> 00:00:54,480
At one point, of course, you get the firebase all instant and then you can go ahead and use this code

14
00:00:54,480 --> 00:01:00,430
here in order to sign in the email with the user, with an email and a password or so.

15
00:01:00,460 --> 00:01:05,370
Please try to do that, try to implement the Sinon feature in this sign an activity.

16
00:01:07,580 --> 00:01:10,880
All right, so this time I'm going to just follow along here.

17
00:01:11,090 --> 00:01:18,560
I'm just going to use the documentation to create this new light and variable and we need to go to our

18
00:01:18,560 --> 00:01:21,350
sign in activity, so.

19
00:01:22,650 --> 00:01:29,880
And here, activities and and, uh, sign in activity, then we need to create this plate in a variable

20
00:01:30,300 --> 00:01:32,490
that we want to initialize later on.

21
00:01:32,500 --> 00:01:40,680
So we need to import firebase authentication and then so we can either set off in uncreate or we can

22
00:01:40,680 --> 00:01:43,830
do it at the moment when we actually use the function.

23
00:01:45,880 --> 00:01:50,470
So either way is fine, I think just doing it here is going to be fine as well.

24
00:01:52,330 --> 00:01:56,370
So let's just said the get instant's here.

25
00:01:59,190 --> 00:02:04,380
Why those all get instance, all right, and now we, of course, need to have a function which allows

26
00:02:04,380 --> 00:02:05,760
us to sign in.

27
00:02:06,040 --> 00:02:07,950
So how do we want to call it?

28
00:02:07,980 --> 00:02:11,100
Well, I'm just going to call it sign in.

29
00:02:12,330 --> 00:02:22,140
Registered user, so private fund sign in registered user, you could, of course, just call it sign

30
00:02:22,140 --> 00:02:24,480
and user, that would be fine as well.

31
00:02:24,690 --> 00:02:28,580
So now let's go back and check the code here.

32
00:02:29,100 --> 00:02:33,810
So it says Volle, current user of current user check if user is signed in.

33
00:02:34,050 --> 00:02:35,190
So this is how you can check.

34
00:02:35,190 --> 00:02:37,020
If these are signed, then we will do that later on.

35
00:02:37,230 --> 00:02:39,230
But what's important is this part here.

36
00:02:39,240 --> 00:02:42,990
So where we sign in the user with email and password.

37
00:02:45,290 --> 00:02:53,150
So first of all, of course, we need to have the email and password, so VUL e-mail string that will

38
00:02:53,150 --> 00:03:02,420
be ETTY email, text to string and then we trem as well.

39
00:03:02,750 --> 00:03:06,770
So actually it's the same as we had it in the sign up functionality.

40
00:03:07,170 --> 00:03:09,380
So here we only need email and password.

41
00:03:09,380 --> 00:03:15,800
So let's just copy those two over to our sign and activity because they are really just the same with

42
00:03:15,800 --> 00:03:19,270
just trimming an empty space at the end.

43
00:03:19,670 --> 00:03:25,550
Then we need to validate the form and we're going to validate it in a very similar way as we've done

44
00:03:25,550 --> 00:03:25,790
here.

45
00:03:25,790 --> 00:03:28,190
So private fund, validate form.

46
00:03:28,510 --> 00:03:33,720
Let's just copy that and use it in our sign in activity as well.

47
00:03:34,430 --> 00:03:36,380
So here I'm just going to create one.

48
00:03:36,710 --> 00:03:41,860
But the difference is that I'm going to not use the name here.

49
00:03:41,870 --> 00:03:45,220
So when signing in, we just need to email and password, right.

50
00:03:45,230 --> 00:03:47,300
So we don't need to have the user name as well.

51
00:03:47,960 --> 00:03:52,760
And here, of course, we can then get rid of this whole part here.

52
00:03:54,320 --> 00:04:02,120
And also, we need to make sure that our class is inheriting from base activity because in base activity,

53
00:04:02,120 --> 00:04:08,540
that's where we set up everything that we can now use for the snack bar.

54
00:04:08,660 --> 00:04:13,780
So show our snack bar is what we prepared in our base activity and now we can reuse it here.

55
00:04:14,000 --> 00:04:15,250
So now we have validated for.

56
00:04:15,650 --> 00:04:21,800
OK, so at this point we can validate the form with the email and password that we have from the user.

57
00:04:21,829 --> 00:04:31,910
So if email and password are validated, so validate form with email and password, if that is true,

58
00:04:32,240 --> 00:04:35,360
then we want to sign in the user.

59
00:04:35,600 --> 00:04:36,620
So invalidate form.

60
00:04:36,630 --> 00:04:41,570
We just checked if the user has entered anything at all, if it's empty, then we just want to let him

61
00:04:41,570 --> 00:04:42,950
know, hey, you need to enter something.

62
00:04:43,160 --> 00:04:49,640
But otherwise we're going to be fine with whatever he has entered and then we can do the authentication.

63
00:04:50,710 --> 00:04:58,220
Of course, we can also first show the progress dialogue where we just let the user know, hey, please

64
00:04:58,220 --> 00:04:58,490
wait.

65
00:04:58,520 --> 00:05:01,460
So actually it's going to be the same as and sign up.

66
00:05:02,790 --> 00:05:08,460
And it's a little more because we also need to get the resources, get string and so forth, so let's

67
00:05:08,460 --> 00:05:12,310
do the same thing here and it's almost the same function.

68
00:05:12,330 --> 00:05:17,670
So the Sinon registered users almost or Disvalue they form, actually, it's almost the same function

69
00:05:17,670 --> 00:05:20,640
as our sign up, but slightly different still.

70
00:05:20,920 --> 00:05:28,140
OK, now we need to make sure that email is the right one because it is the one from sign ups.

71
00:05:28,140 --> 00:05:30,540
So we need to make sure that it's the one from sign in.

72
00:05:30,780 --> 00:05:34,500
So any email we can see we have to hear.

73
00:05:34,980 --> 00:05:38,520
So now what we can do is we can rename one of them.

74
00:05:38,730 --> 00:05:45,590
So let's rename the one from our sign up or actually let's go for the one inside.

75
00:05:45,600 --> 00:05:47,280
And I think that makes more sense.

76
00:05:47,850 --> 00:05:48,420
So.

77
00:05:49,500 --> 00:05:59,580
Here it's on our resources lay out sign in and here to Ed, text's are the ones that we are interested

78
00:05:59,580 --> 00:05:59,950
in, right?

79
00:05:59,970 --> 00:06:00,330
So.

80
00:06:01,790 --> 00:06:09,350
Text fields lay out here, eat email on the score, Sinon, and then.

81
00:06:11,240 --> 00:06:13,580
ET password on the score, sign it.

82
00:06:13,760 --> 00:06:15,090
So how I'm going to call them.

83
00:06:16,070 --> 00:06:16,580
All right.

84
00:06:17,440 --> 00:06:21,840
Of course, you could use sign on the score in to be more precise, so that.

85
00:06:22,850 --> 00:06:25,430
It's even happier here, just like that.

86
00:06:25,880 --> 00:06:36,230
OK, so now inside and we need to make sure that it's E.T. email, sign in and password sign it, OK,

87
00:06:36,260 --> 00:06:39,350
because otherwise we will use the one from sign up.

88
00:06:40,140 --> 00:06:45,730
OK, so at this point we can go ahead and run our code.

89
00:06:46,100 --> 00:06:51,220
So here we can now finally run the code from the website.

90
00:06:52,310 --> 00:06:53,390
So let's copy this.

91
00:06:55,700 --> 00:06:58,400
And then added in here.

92
00:07:00,080 --> 00:07:05,620
OK, so I'll tell you why I'm not going to use that log.

93
00:07:05,930 --> 00:07:07,430
Well, we can.

94
00:07:08,430 --> 00:07:10,330
His dad can import it.

95
00:07:11,070 --> 00:07:12,810
We don't have a tag yet.

96
00:07:13,930 --> 00:07:18,760
That's also something that we might want to import, so import toast update wise, what we're going

97
00:07:18,760 --> 00:07:19,280
to use.

98
00:07:19,930 --> 00:07:22,260
So here they have tag as well.

99
00:07:24,280 --> 00:07:28,090
So I'm just going to call this tag sign in.

100
00:07:31,100 --> 00:07:34,580
And here as well, sign an.

101
00:07:37,060 --> 00:07:40,070
Also, by the way, this vile user of current user.

102
00:07:41,050 --> 00:07:44,910
Well, that's fine, but we're not using it right now, so we don't need it yet.

103
00:07:46,860 --> 00:07:54,180
And also here we say authentication failed, but, well, we are providing the exception in the Lochhead,

104
00:07:54,190 --> 00:07:55,420
so I think that's going to be fine.

105
00:07:56,160 --> 00:08:02,330
OK, so this is very similar to what we had before in our sign up here.

106
00:08:02,340 --> 00:08:08,130
Of course, we could also, instead of toasting the whole error message to the user, which he doesn't

107
00:08:08,130 --> 00:08:13,020
understand probably, or which doesn't make sense to him, we could replace that, of course, with

108
00:08:13,020 --> 00:08:15,620
also registration failed or something like that.

109
00:08:15,930 --> 00:08:17,790
So let's just do that real quick here.

110
00:08:18,060 --> 00:08:20,940
Registration failed.

111
00:08:22,850 --> 00:08:33,049
All right, so now we can go ahead and test it, so let's see if we can sign in our user.

112
00:08:34,840 --> 00:08:40,630
Once we click the button, but of course, we still need to fix the error that we have here.

113
00:08:40,750 --> 00:08:49,660
So as it seems, I'm liking one curly bracket at one point when I copy to validate form, I didn't copy

114
00:08:49,660 --> 00:08:50,380
it correctly.

115
00:08:50,890 --> 00:08:57,430
Also, something that we probably should also do is hide our progress dialogue at one point because

116
00:08:57,430 --> 00:09:02,410
here we show it and if we don't hide it, then it's not going to be very good.

117
00:09:02,590 --> 00:09:06,560
Look at your app, so let's hide it directly here.

118
00:09:06,760 --> 00:09:12,700
So once it's completed, so high progress, dialogue and then.

119
00:09:15,250 --> 00:09:20,890
Let's move over to our main activity, OK, just so that we see that it actually works.

120
00:09:20,920 --> 00:09:31,960
So start activity, intent from this to the main activity, colon, colon, class, Java.

121
00:09:33,520 --> 00:09:35,300
And intent needs to be important.

122
00:09:35,320 --> 00:09:36,260
Let's do that real quick.

123
00:09:36,550 --> 00:09:41,500
OK, so once we are successfully signed, then we want to move over to our main activity here.

124
00:09:42,460 --> 00:09:47,890
Now, of course, there's one last thing to do, and that is to add functionality to the button, because

125
00:09:47,890 --> 00:09:53,020
currently when we sign in, when we click on the sign in button activity, sign in.

126
00:09:53,020 --> 00:09:57,100
So let's see, we have this button called button sign in.

127
00:09:57,580 --> 00:09:59,320
If we clicked this one, nothing happened.

128
00:09:59,340 --> 00:10:06,870
So let's add an unclipped listen to it sign in said on Click Listener.

129
00:10:07,600 --> 00:10:12,730
And here we will use to sign in registered user function functio.

130
00:10:13,690 --> 00:10:15,340
So this functionality just prepare.

131
00:10:16,260 --> 00:10:21,240
All right, and then there's one bug that I found as well when running the application so you can test

132
00:10:21,240 --> 00:10:21,820
it, run it.

133
00:10:22,140 --> 00:10:27,220
The thing is, our set up action bar is really just a copy of the setup action bar and the sign up activity.

134
00:10:27,240 --> 00:10:29,700
And when you do that, you have to be careful.

135
00:10:29,700 --> 00:10:30,900
And I wasn't careful enough.

136
00:10:31,110 --> 00:10:36,480
So you can see set up said support action bar for toolbar sign up activity.

137
00:10:36,810 --> 00:10:40,050
Of course, it should be for our toolbar sign in activity.

138
00:10:40,650 --> 00:10:44,440
And the same goes down here with the set navigation on Click Listener.

139
00:10:44,760 --> 00:10:50,760
So if you do these kind of things, copy and pasting, you always need to double check for changes.

140
00:10:50,970 --> 00:10:56,280
But at the point when you test it, that's latest word, the latest moment when you realize those things.

141
00:10:56,280 --> 00:10:57,930
So no worries there.

142
00:10:57,990 --> 00:10:58,790
It's still fine.

143
00:10:58,800 --> 00:10:59,930
So let's run it again.

144
00:11:00,270 --> 00:11:02,730
Now, we should hopefully get to design the activity.

145
00:11:04,740 --> 00:11:05,940
All right, so there we are.

146
00:11:07,470 --> 00:11:09,300
OK, so this seems to work.

147
00:11:10,350 --> 00:11:12,240
Let's test Dennis at.

148
00:11:14,040 --> 00:11:20,550
Gmail dot com password was super secure, sign in, please wait.

149
00:11:21,890 --> 00:11:26,990
And we are moved over to the hello world screen, which is our main activity, so as it seems, this

150
00:11:27,020 --> 00:11:27,430
worked.

151
00:11:27,770 --> 00:11:30,780
So we are now logged in, which is pretty cool.

152
00:11:31,130 --> 00:11:35,250
So now you can see how you can sign up a user and how you can sign in a user.

153
00:11:35,540 --> 00:11:40,780
And now we can go ahead and display stuff to the user that is relevant to him.

154
00:11:41,480 --> 00:11:45,740
So that's, of course, what we have to set up step by step, because there is a lot of functionality

155
00:11:45,740 --> 00:11:49,280
that will follow and we haven't even touched the database yet.

156
00:11:49,290 --> 00:11:52,520
So that's super interesting stuff that we're going to look at later on.

157
00:11:53,990 --> 00:11:59,720
So in the next video, first of all, we are going to create a new entry in the database.

158
00:11:59,720 --> 00:12:02,120
So we're going to create a new database itself.

159
00:12:02,120 --> 00:12:02,340
Right.

160
00:12:02,360 --> 00:12:09,450
So using the firestorm and the next video and then we're going to use the user class.

161
00:12:09,450 --> 00:12:12,290
So we're going to create a new model and so forth.

162
00:12:12,300 --> 00:12:14,280
So let's go ahead and check that out.

163
00:12:14,300 --> 00:12:15,090
See you in the next one.

164
00:12:15,110 --> 00:12:22,070
And by the way, I hope you were successful in writing this code and you fixed the box that we have

165
00:12:22,070 --> 00:12:26,050
here and everything, because at that point, I would expect you to be able to do that.

166
00:12:26,360 --> 00:12:33,770
So if you weren't able to do that, then try to do and we'll create another app where you do the sign

167
00:12:33,770 --> 00:12:41,300
in and sign up functionality from scratch all by yourself using the documentation only because this

168
00:12:41,300 --> 00:12:47,150
is going to be super relevant and important when it comes to developing applications for customers in

169
00:12:47,150 --> 00:12:50,030
the future or even for your own ideas that you have.

170
00:12:50,360 --> 00:12:52,460
Because running into errors is normal.

171
00:12:52,460 --> 00:12:53,270
It's no problem.

172
00:12:53,270 --> 00:12:54,890
Running to bugs is also normal.

173
00:12:55,190 --> 00:12:56,420
It's important to fix them.

174
00:12:56,450 --> 00:13:01,370
It's important to check out documentations, to read through the Internet, to find solutions and so

175
00:13:01,370 --> 00:13:01,670
forth.

176
00:13:02,180 --> 00:13:02,600
All right.

177
00:13:02,930 --> 00:13:03,670
See you in the next one.

