1
00:00:00,420 --> 00:00:00,800
Okay.

2
00:00:00,810 --> 00:00:08,340
And one more thing that I want to add to our application is the check for the user on the landing page.

3
00:00:08,340 --> 00:00:11,610
So that's something that students have been asking.

4
00:00:11,790 --> 00:00:20,850
They're like, look, if the user has currently logged in, why we still display the landing page.

5
00:00:20,900 --> 00:00:27,030
Colin just set up some kind of functionality where if the user exists, then basically we right away

6
00:00:27,030 --> 00:00:30,390
navigate back to the dashboard just to showcase that.

7
00:00:31,050 --> 00:00:32,189
Let me log.

8
00:00:33,580 --> 00:00:35,170
In my application.

9
00:00:37,090 --> 00:00:37,660
Yep.

10
00:00:38,960 --> 00:00:40,280
As you can see, everything.

11
00:00:40,960 --> 00:00:42,510
And I was successful.

12
00:00:42,530 --> 00:00:47,330
And then if let's say I go here to forward slash landing.

13
00:00:48,120 --> 00:00:50,010
I'll be able to navigate there.

14
00:00:50,550 --> 00:00:57,060
And some students say that a better user experience would be if, let's say, right away, we kick back

15
00:00:57,060 --> 00:00:58,560
the user to the dashboard.

16
00:00:59,400 --> 00:01:02,530
And that is something we can do effectively.

17
00:01:02,550 --> 00:01:03,710
Here's the plan.

18
00:01:03,720 --> 00:01:06,120
We want to get the user from user context.

19
00:01:06,120 --> 00:01:10,980
And of course, we need to get the user app context from the app context.

20
00:01:11,220 --> 00:01:19,020
We also want to get the navigate component and we just want to set up the check here on top of the return.

21
00:01:19,320 --> 00:01:25,100
We want to wrap this in a React fragment because those are two adjacent elements over here.

22
00:01:25,110 --> 00:01:30,510
So therefore it will set up the React Fragment and then inside of it we're going to go with user.

23
00:01:30,780 --> 00:01:32,870
And then we'll navigate if the user exists.

24
00:01:32,880 --> 00:01:37,200
If not, then we'll display rest of the code.

25
00:01:37,770 --> 00:01:40,400
And just one last thing that I want to mention.

26
00:01:40,410 --> 00:01:43,740
This is not going to happen in some time.

27
00:01:44,130 --> 00:01:50,520
This will happen immediately, unlike the register page where remember we had that code.

28
00:01:51,560 --> 00:01:54,240
For the use effect, correct?

29
00:01:54,260 --> 00:01:59,210
Where we are checking for the user and then with the set timeout, we essentially navigate it.

30
00:01:59,240 --> 00:02:00,290
This is not the case.

31
00:02:00,290 --> 00:02:02,240
This will happen immediately.

32
00:02:02,480 --> 00:02:04,850
So let's go to the landing.

33
00:02:04,850 --> 00:02:07,450
One, we want to import both of those things.

34
00:02:07,460 --> 00:02:13,040
Like I said, we want to get the navigate from React and we already have the links so we can cheat the

35
00:02:13,040 --> 00:02:13,670
little bit.

36
00:02:14,450 --> 00:02:16,010
We can say navigate.

37
00:02:17,110 --> 00:02:17,870
Navigate.

38
00:02:17,890 --> 00:02:18,430
Hook.

39
00:02:18,550 --> 00:02:18,820
Great.

40
00:02:18,820 --> 00:02:19,360
Good.

41
00:02:19,480 --> 00:02:26,290
And then let's also set up the import for use app context.

42
00:02:27,060 --> 00:02:33,390
So let's go here with import than use context.

43
00:02:33,400 --> 00:02:34,920
Yep, that's the important.

44
00:02:34,950 --> 00:02:39,630
And on top of it, let's get the user from our main context.

45
00:02:39,630 --> 00:02:47,130
So user manual is equal to use context, we want to invoke the hook and then like I said, we are returning

46
00:02:47,130 --> 00:02:49,110
to adjacent elements.

47
00:02:49,110 --> 00:02:54,510
So we want to go with React Fragment, which essentially will allow us to do that.

48
00:02:54,840 --> 00:02:56,460
That is going to be our main return.

49
00:02:56,510 --> 00:02:58,710
So let me put it here.

50
00:02:59,430 --> 00:03:04,020
And then on top of the rapper, simply want to set up the check for the user.

51
00:03:04,350 --> 00:03:06,690
If the user exists, awesome.

52
00:03:07,320 --> 00:03:11,250
Want to navigate to and then this is really up to you.

53
00:03:11,250 --> 00:03:12,810
I'm going to go to the.

54
00:03:13,640 --> 00:03:14,190
Homepage.

55
00:03:14,210 --> 00:03:18,110
Like, so let's say that and then let's try it out.

56
00:03:18,110 --> 00:03:24,950
So if everything is correct, if I have the cookie and all that, by the way, let me check the application.

57
00:03:24,950 --> 00:03:27,920
Notice this is the cookie, if everything is correct.

58
00:03:28,790 --> 00:03:35,570
If let's say I go to the landing and I say, no, I technically don't need the cookie as long as the

59
00:03:35,570 --> 00:03:39,860
user is there, but I'm just showcasing what would happen if I would refresh notice.

60
00:03:40,070 --> 00:03:46,280
So we go technically to the landing, but we right away kick to user back.

61
00:03:46,980 --> 00:03:48,720
That's essentially what's happening.

62
00:03:48,870 --> 00:03:51,060
So the user doesn't stay there long.

63
00:03:51,570 --> 00:03:56,070
And with this in place now, we can worry about the logout feature.

