1
00:00:00,500 --> 00:00:06,860
Welcome back and this video, we are going to see how we can lock in the user automatically and send

2
00:00:06,860 --> 00:00:11,990
him directly to the main activity instead of showing him the login screen once again.

3
00:00:12,350 --> 00:00:17,560
And that is going to be based on whether there is a user ID for the current user.

4
00:00:17,870 --> 00:00:20,970
So Firebase takes care of that automatically.

5
00:00:21,230 --> 00:00:22,330
That's the power here.

6
00:00:22,340 --> 00:00:24,230
We don't need to do that ourselves.

7
00:00:24,230 --> 00:00:29,600
So we don't need you to download a token and then the token somewhere and all of those kind of things.

8
00:00:29,900 --> 00:00:32,659
But the token is generated in the backend.

9
00:00:32,840 --> 00:00:35,150
So it's generated on the firebase side.

10
00:00:35,330 --> 00:00:37,820
So we don't need to do that sort of powers here.

11
00:00:37,820 --> 00:00:42,740
Or what makes it easier for us is that we can just check if there is an instance for the current user

12
00:00:42,950 --> 00:00:50,450
and then we can either get the user ID or we will just return an empty string and we can then use that

13
00:00:50,450 --> 00:00:55,730
in order to either log in the user directly and send him directly to the main activity.

14
00:00:55,730 --> 00:01:02,780
Or we can just send him to the login activity or the intro activity that we have here where he can then

15
00:01:02,780 --> 00:01:04,650
decide to either register or log in.

16
00:01:05,290 --> 00:01:09,100
OK, so let's go ahead and build the code for that.

17
00:01:09,110 --> 00:01:14,630
So first of all, what I'm going to do is I'm going to pretty much copy this code here.

18
00:01:15,740 --> 00:01:23,360
And store it in a variable, which I'm going to call current user, which will be Firebase get instant's

19
00:01:23,360 --> 00:01:32,030
current user, so we will use that in order to then check if the current user is null or not, because

20
00:01:32,030 --> 00:01:33,080
this can return null.

21
00:01:33,350 --> 00:01:36,920
And if it does return now, it means that there is no current user.

22
00:01:37,280 --> 00:01:37,720
All right.

23
00:01:37,970 --> 00:01:43,730
So let's go ahead and create a helper variable, which will then be the one that we will return.

24
00:01:44,240 --> 00:01:46,320
So I will show you what I mean in a second.

25
00:01:46,550 --> 00:01:55,550
So this will check if the current user is not null, because if that's the case, then go ahead and

26
00:01:55,550 --> 00:01:56,210
assign.

27
00:01:57,280 --> 00:02:06,940
The current user I.D., the value of the current user thought you ID, so you maybe remember how we

28
00:02:06,940 --> 00:02:13,430
used you ID here just a second ago and we had to force it, as you can see, so we had to force it with

29
00:02:13,430 --> 00:02:14,740
the double exclamation mark.

30
00:02:14,980 --> 00:02:18,740
But now we don't need to do that because we check if it's empty or not.

31
00:02:19,300 --> 00:02:27,250
So this time we just get the current user and if the current user is empty, then we will return an

32
00:02:27,250 --> 00:02:27,930
empty string.

33
00:02:27,940 --> 00:02:34,150
So we would just say, well, actually, we don't even need to do that because it's going to be empty

34
00:02:34,150 --> 00:02:34,570
anyways.

35
00:02:34,570 --> 00:02:34,820
Right.

36
00:02:35,080 --> 00:02:42,400
So now we can go ahead and return whatever current user ideas, because at that point it's either going

37
00:02:42,400 --> 00:02:49,270
to be an empty string or it's going to be the unique user ID, which we then, of course, can use in

38
00:02:49,270 --> 00:02:55,930
order to download the right information about the user, such as the boards that he has, the tasks

39
00:02:55,930 --> 00:02:59,680
that are assigned to him, and all of the user information that we have about him.

40
00:03:01,130 --> 00:03:07,400
Now, of course, where we want to do the sending over, so the.

41
00:03:08,910 --> 00:03:13,220
Activity intent is in our interest to you.

42
00:03:13,260 --> 00:03:22,620
So here is where we want to send the user either to the intro activity or to our main activity and then

43
00:03:22,620 --> 00:03:26,580
the main activity in the end, we want to have all of the different boards and everything.

44
00:03:27,030 --> 00:03:27,440
All right.

45
00:03:27,690 --> 00:03:32,130
So here what we have is the splash activity.

46
00:03:32,130 --> 00:03:33,650
So we don't want to go to the intro.

47
00:03:33,660 --> 00:03:36,900
We want to go to splash here.

48
00:03:37,620 --> 00:03:39,090
We had this little handle, right.

49
00:03:39,510 --> 00:03:44,660
And we postulate started an activity and sent the user to the intro activity.

50
00:03:45,030 --> 00:03:48,420
But now what we're going to do is we are going to.

51
00:03:49,730 --> 00:03:58,610
Check if the current user I.D., so here, current user ID, I'm going to give it the same name and

52
00:03:58,610 --> 00:04:04,030
here we take the first class and get the current user I.D..

53
00:04:04,790 --> 00:04:08,180
So this will either be an empty string or it will be the user ID.

54
00:04:08,300 --> 00:04:11,210
So the Joujou ID that is stored in the backpack and.

55
00:04:12,540 --> 00:04:13,800
So this number here.

56
00:04:14,130 --> 00:04:22,200
All right, so here we can then check if current user I.D. is not empty, all right?

57
00:04:22,200 --> 00:04:25,840
Because if it's not empty, we know that we have a user that is locked in.

58
00:04:25,860 --> 00:04:33,060
So what we can do is we can send them directly to the main activity in which we then will display,

59
00:04:33,540 --> 00:04:34,380
for example, the.

60
00:04:35,420 --> 00:04:35,820
Right.

61
00:04:36,300 --> 00:04:45,270
And then if we don't have a user ID, so if it's empty, then we want to send them to the interactivity

62
00:04:45,270 --> 00:04:50,370
where he can then choose to either register or log in or sign it.

63
00:04:50,970 --> 00:04:53,830
OK, so that is pretty much it.

64
00:04:53,880 --> 00:04:55,320
That's our splash activity.

65
00:04:55,330 --> 00:04:58,020
Now it will take care of everything.

66
00:04:58,020 --> 00:05:02,250
It will send us over to the right activity within two point five seconds.

67
00:05:02,550 --> 00:05:08,460
So now let's test it and see if our application will directly send us to this activity instead of sending

68
00:05:08,460 --> 00:05:12,580
us to the login activity or the interactivity.

69
00:05:13,410 --> 00:05:13,860
All right.

70
00:05:13,860 --> 00:05:18,360
So there we are approaching Menasche and we were sent directly to the main activity.

71
00:05:18,790 --> 00:05:19,390
All right.

72
00:05:19,410 --> 00:05:21,720
So this means that we are still logged in.

73
00:05:22,140 --> 00:05:26,490
And, of course, we would need a log out button to allow the user to log out.

74
00:05:26,490 --> 00:05:29,800
But we will add all of those features later on.

75
00:05:30,360 --> 00:05:32,370
OK, so that was it for this video.

76
00:05:32,400 --> 00:05:33,330
See you in the next one.

