Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,300 --> 00:00:03,900
[Maximilian Schwarzmuller} No for logging users out,
2
00:00:03,900 --> 00:00:07,180
we got this log out button here in the main navigation
3
00:00:07,180 --> 00:00:10,310
and at the moment, this button isn't doing anything.
4
00:00:10,310 --> 00:00:13,750
Now, what do we want to do when we click this button?
5
00:00:13,750 --> 00:00:17,830
You might think that we send some requests to Firebase
6
00:00:17,830 --> 00:00:20,750
but keep in mind that the main idea
7
00:00:20,750 --> 00:00:24,130
when using this authentication token approach,
8
00:00:24,130 --> 00:00:28,140
was that the server does not store any information
9
00:00:28,140 --> 00:00:30,570
about the logged in client.
10
00:00:30,570 --> 00:00:34,110
So actually, we don't need to send any requests
11
00:00:34,110 --> 00:00:37,380
because Firebase doesn't know and doesn't care
12
00:00:37,380 --> 00:00:40,113
that we are, or were logged in.
13
00:00:41,060 --> 00:00:44,740
The only thing we need to change when we log out
14
00:00:44,740 --> 00:00:46,650
is our state.
15
00:00:46,650 --> 00:00:48,540
We just have to make sure
16
00:00:48,540 --> 00:00:52,910
that in this context, API, we clear our token.
17
00:00:52,910 --> 00:00:55,910
We set it back to an empty string or to null.
18
00:00:55,910 --> 00:00:58,793
That's the only thing that matters here.
19
00:01:00,570 --> 00:01:03,410
And therefore here in main navigation JS,
20
00:01:03,410 --> 00:01:06,510
we already have access to all the context
21
00:01:06,510 --> 00:01:09,470
we therefore only need to add a number function here,
22
00:01:09,470 --> 00:01:13,130
the log-out handler function, for example
23
00:01:13,130 --> 00:01:15,450
and in that log out handler function,
24
00:01:15,450 --> 00:01:20,090
I'll call off context, log out, which is a function
25
00:01:20,090 --> 00:01:24,540
we already prepared in our context provider.
26
00:01:24,540 --> 00:01:28,610
There in the log out handler, we set the token to null
27
00:01:28,610 --> 00:01:33,610
and that's the handler which we call when we call log out.
28
00:01:33,770 --> 00:01:36,300
And that's the only thing we got to do here.
29
00:01:36,300 --> 00:01:39,670
So, then we just need to bind this log out handler
30
00:01:39,670 --> 00:01:44,223
to this button here with on click and we should be good.
31
00:01:45,260 --> 00:01:48,770
If I save that and I click log out
32
00:01:48,770 --> 00:01:52,023
you see the UI changes once I do log out.
33
00:01:53,250 --> 00:01:55,810
Now, of course we have an issue here though.
34
00:01:55,810 --> 00:02:00,750
If I quickly log back in, if I go to the profile page
35
00:02:00,750 --> 00:02:02,360
and I click log out,
36
00:02:02,360 --> 00:02:04,220
the main navigation changes
37
00:02:04,220 --> 00:02:06,970
but I stay on that profile page.
38
00:02:06,970 --> 00:02:09,660
I'm not redirected away from there.
39
00:02:09,660 --> 00:02:13,993
And that's something we might want to avoid here.
40
00:02:15,190 --> 00:02:16,540
Now, to avoid that,
41
00:02:16,540 --> 00:02:21,540
we can of course also redirect the user here if we want to
42
00:02:22,640 --> 00:02:25,250
but I won't do that here.
43
00:02:25,250 --> 00:02:28,140
And I won't do that here because in the next lecture
44
00:02:28,140 --> 00:02:30,920
I want to dive into another important topic
45
00:02:30,920 --> 00:02:33,690
which will solve this problem for us.
46
00:02:33,690 --> 00:02:38,290
And that will be navigation guards, protecting pages
47
00:02:38,290 --> 00:02:40,903
in our front end react auth.
3807
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.