Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,210 --> 00:00:04,200
In this lecture, we're going to persist the user authentication.
2
00:00:04,200 --> 00:00:07,880
Previously we waited for Firebase to initialize.
3
00:00:07,890 --> 00:00:14,010
At this point we can check with Firebase if the user is logged in, we're going to perform this check
4
00:00:14,010 --> 00:00:16,500
in the earliest phase of our application.
5
00:00:16,500 --> 00:00:19,860
The app component is considered the root component.
6
00:00:19,860 --> 00:00:23,280
This component is the first component that's initialized.
7
00:00:23,310 --> 00:00:25,560
Open the app component file.
8
00:00:27,990 --> 00:00:34,650
First we're going to need the state import the map readable store function from the penny a package.
9
00:00:36,710 --> 00:00:39,170
Next import the user store.
10
00:00:41,270 --> 00:00:44,030
Inside the components configuration object.
11
00:00:44,030 --> 00:00:45,950
Add the computed object.
12
00:00:48,100 --> 00:00:52,300
Called the map writable state function with the spread operator.
13
00:00:54,410 --> 00:00:56,300
Pass in the user store.
14
00:00:58,360 --> 00:01:02,350
Lastly, add an array with the user logged in state.
15
00:01:04,590 --> 00:01:07,620
Overall, we're mapping the state to the component.
16
00:01:07,650 --> 00:01:09,750
These are steps we've taken before.
17
00:01:09,780 --> 00:01:15,680
It's time to start checking the authentication status of the user inside the exported object.
18
00:01:15,690 --> 00:01:18,270
We're going to define the created method.
19
00:01:20,480 --> 00:01:26,540
This life cycle function is called when the component is created, as you learned in a previous lecture.
20
00:01:26,690 --> 00:01:30,520
In this function, we're going to perform a conditional statement.
21
00:01:30,530 --> 00:01:33,400
The condition will check if the user is logged in.
22
00:01:33,410 --> 00:01:35,810
If they are, we'll update the state.
23
00:01:35,840 --> 00:01:39,260
Otherwise, we won't do anything at the top of the script.
24
00:01:39,260 --> 00:01:39,810
BLOCK.
25
00:01:39,830 --> 00:01:43,940
Import the authentication service from the Firebase File.
26
00:01:46,070 --> 00:01:51,920
This service will help us detect the authentication of the user back in the lifecycle function.
27
00:01:51,920 --> 00:01:53,630
Add a conditional statement.
28
00:01:55,700 --> 00:02:00,830
Next set the condition to the following of dot current user.
29
00:02:03,160 --> 00:02:08,169
The current user property holds information about the user currently logged in.
30
00:02:08,169 --> 00:02:11,230
If they're not logged in, it'll be set to null.
31
00:02:11,260 --> 00:02:17,050
If the variable is an object filled with properties, this will evaluate to a truth value.
32
00:02:17,080 --> 00:02:23,870
The last step is to set the user logged in state property to true within the conditional statement.
33
00:02:23,890 --> 00:02:25,210
Update the state.
34
00:02:27,370 --> 00:02:29,590
Let's check if everything is working.
35
00:02:29,950 --> 00:02:31,840
Open the app in your browser.
36
00:02:33,730 --> 00:02:36,150
We'll start by refreshing the page.
37
00:02:36,160 --> 00:02:38,020
The app will start normally.
38
00:02:38,050 --> 00:02:42,580
It won't start until the Firebase event we're listening for is fired off.
39
00:02:42,580 --> 00:02:46,390
The event is emitted immediately after the page loads.
40
00:02:46,390 --> 00:02:52,060
We don't have to worry about the app never loading because we're guaranteed that the callback function
41
00:02:52,060 --> 00:02:54,010
will execute at least once.
42
00:02:54,400 --> 00:02:55,900
Open the developer tools.
43
00:02:55,900 --> 00:03:01,620
If you haven't already under the View panel, a new tab should be available called Pinna.
44
00:03:01,690 --> 00:03:05,890
This tab contains a complete list of stores within our application.
45
00:03:05,890 --> 00:03:08,890
As you can see, the modal store is available.
46
00:03:08,890 --> 00:03:12,430
If you can't find the user store, that's perfectly fine.
47
00:03:12,430 --> 00:03:15,430
Chances are you're not logged into the application.
48
00:03:15,430 --> 00:03:17,830
I'm going to quickly register an account.
49
00:03:23,000 --> 00:03:25,520
Next, I will refresh the page.
50
00:03:27,670 --> 00:03:31,730
If we look at the developer tools, the user store has been added.
51
00:03:31,750 --> 00:03:37,120
Taking a closer look, the user logged in state property has been set to true.
52
00:03:37,150 --> 00:03:38,740
Let's refresh the page.
53
00:03:40,390 --> 00:03:41,030
Great.
54
00:03:41,050 --> 00:03:44,380
We can refresh the page as many times as we want.
55
00:03:44,410 --> 00:03:45,950
We'll always be logged in.
56
00:03:45,970 --> 00:03:48,640
Let's try testing if the opposite is true.
57
00:03:48,970 --> 00:03:53,860
During the authentication process, Firebase will store a token on the client.
58
00:03:53,890 --> 00:03:58,780
You never have to worry about the token because it's managed for you by the sdhc.
59
00:03:58,810 --> 00:04:05,410
However, that doesn't mean you don't have access to it, and the developer tools switch to the application
60
00:04:05,410 --> 00:04:06,070
panel.
61
00:04:08,300 --> 00:04:13,080
The application panel allows you to view the metadata of your application.
62
00:04:13,100 --> 00:04:18,260
This includes things like storage service workers or the manifest document.
63
00:04:18,290 --> 00:04:23,030
We're interested in viewing the storage for the application on the sidebar.
64
00:04:23,060 --> 00:04:25,520
There are various storage solutions.
65
00:04:25,520 --> 00:04:28,410
Firebase uses indexed DB.
66
00:04:28,460 --> 00:04:32,270
Under this storage, we'll find the Firebase Local Storage.
67
00:04:32,270 --> 00:04:33,290
Click on it.
68
00:04:33,380 --> 00:04:38,720
Firebase will store the user's information under a key called Firebase Auth.
69
00:04:38,870 --> 00:04:42,830
Under the value column, there's an extensive list of properties.
70
00:04:42,830 --> 00:04:48,110
This location is where Firebase is storing the user's authentication information.
71
00:04:48,110 --> 00:04:51,260
We'll want to remove this to start with a clean slate.
72
00:04:51,260 --> 00:04:56,240
Without a token, Firebase will not be able to verify the user is logged in.
73
00:04:56,240 --> 00:04:59,150
It'll default to saying the user is logged out.
74
00:04:59,480 --> 00:05:01,820
We have two ways of clearing the data.
75
00:05:01,820 --> 00:05:06,500
We can select the row and then click on this button that says Delete Selected.
76
00:05:06,800 --> 00:05:12,500
Alternatively, we can switch to the Clear Data tab under the application section.
77
00:05:12,500 --> 00:05:17,870
In the sidebar, this town will give you an overview of the data stored from the application.
78
00:05:17,870 --> 00:05:21,530
Scrolling down, you'll come across a button to clear the data.
79
00:05:21,530 --> 00:05:22,460
Click on it.
80
00:05:24,830 --> 00:05:28,790
I prefer to clear the entire data just in case I miss anything.
81
00:05:28,820 --> 00:05:34,400
It'll altogether remove any data associated with our application after doing so.
82
00:05:34,400 --> 00:05:36,170
Let's refresh the page.
83
00:05:38,420 --> 00:05:39,340
The app loads.
84
00:05:39,350 --> 00:05:43,940
Normally we'll switch to the View panel to view the mutation logs.
85
00:05:44,030 --> 00:05:47,300
Unlike before, the user store may not appear.
86
00:05:47,330 --> 00:05:53,300
Alternatively, if it does, the user logged in state property should be set to false.
87
00:05:53,330 --> 00:05:57,420
This is because we removed the user's data from the storage.
88
00:05:57,440 --> 00:06:00,440
Firebase is unable to authenticate the user.
89
00:06:00,470 --> 00:06:03,710
Henceforth, these state does not get updated.
90
00:06:03,740 --> 00:06:06,520
That's exactly what we're looking to accomplish.
91
00:06:06,530 --> 00:06:11,860
We've successfully created an application that persists the user's authentication.
92
00:06:11,870 --> 00:06:14,280
We've completed the registration form.
93
00:06:14,300 --> 00:06:20,930
After ten lectures, we were able to register the user, store their data and persist their log in.
94
00:06:20,960 --> 00:06:23,660
It took a lot of work, but it's well worth it.
95
00:06:23,840 --> 00:06:27,350
In the next lecture we're going to work on the login form.
96
00:06:27,350 --> 00:06:29,480
When you're ready, I'll see you there.
8954
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.