Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,470 --> 00:00:04,160
So far we've done a lot to get the user authenticated.
2
00:00:04,190 --> 00:00:09,380
There are still some issues we'll need to address before we can move onto the login form.
3
00:00:09,590 --> 00:00:13,520
One of those issues is connecting the user with their data.
4
00:00:13,850 --> 00:00:20,090
In Firebase, we're storing the user's information in two separate services, the authentication and
5
00:00:20,330 --> 00:00:21,610
the store service.
6
00:00:21,620 --> 00:00:24,800
At the moment, we don't have a way to connect the two.
7
00:00:24,830 --> 00:00:27,830
We don't know which document belongs to which user.
8
00:00:27,830 --> 00:00:32,960
In the authentication service, there is one common value between the two services.
9
00:00:32,960 --> 00:00:34,640
That would be the email.
10
00:00:34,910 --> 00:00:38,570
I don't recommend using the email to keep track of the user.
11
00:00:38,600 --> 00:00:40,640
It's because emails can change.
12
00:00:40,640 --> 00:00:46,910
If the email changes, we'll have to change the email in the list of users and the database.
13
00:00:46,910 --> 00:00:51,080
We want something that will be consistent once the user has registered.
14
00:00:51,110 --> 00:00:53,930
Luckily, there is a value we can use.
15
00:00:54,110 --> 00:00:58,700
Navigate to the authenticated section in the Firebase console.
16
00:00:58,730 --> 00:01:03,380
Every user is assigned a user uid this value is unique.
17
00:01:03,380 --> 00:01:04,730
It will never change.
18
00:01:04,730 --> 00:01:10,640
We will want to store this value in the database to know which piece of data belongs to which user in
19
00:01:10,640 --> 00:01:12,410
our Firebase sample location.
20
00:01:12,620 --> 00:01:17,750
Likewise via store will assign a unique ID to each document.
21
00:01:17,780 --> 00:01:21,050
Navigate to the database in the Firebase console.
22
00:01:23,040 --> 00:01:25,050
Select the users collection.
23
00:01:25,050 --> 00:01:31,910
If it hasn't been auto selected already in the middle column, we'll find a list of random strings.
24
00:01:31,920 --> 00:01:35,190
These are unique IDs assigned to each document.
25
00:01:35,220 --> 00:01:38,490
The ID is automatically generated for us.
26
00:01:38,490 --> 00:01:40,290
We'll want to change this.
27
00:01:40,290 --> 00:01:47,550
Instead of using a randomly generated ID, we're going to use the ID assigned to the user in the authentication
28
00:01:47,550 --> 00:01:48,360
service.
29
00:01:48,540 --> 00:01:52,080
Before we get started, I want to make one point clear.
30
00:01:52,110 --> 00:01:55,080
This issue is a firebase related issue.
31
00:01:55,080 --> 00:01:56,760
It is not a view issue.
32
00:01:56,790 --> 00:02:02,370
Storing the user in the database and keeping track of their data is something a back end developer has
33
00:02:02,370 --> 00:02:05,370
to worry about as frontend developers.
34
00:02:05,370 --> 00:02:11,460
Our responsibility is to send the data to the correct endpoint and storing the token we receive from
35
00:02:11,460 --> 00:02:12,360
the back end.
36
00:02:12,390 --> 00:02:15,690
The token permits us to interact with the database.
37
00:02:15,690 --> 00:02:18,810
Other than that, everything else is back end related.
38
00:02:18,960 --> 00:02:25,380
However, with that being said, I still want to show you how to accomplish this task with Firebase.
39
00:02:25,380 --> 00:02:28,530
Some of you may want to use it as your back end solution.
40
00:02:28,530 --> 00:02:29,550
That's fine.
41
00:02:29,550 --> 00:02:34,620
Even if you decide to use a different backend, the process on the front end is still the same.
42
00:02:35,100 --> 00:02:36,990
All right, let's get started.
43
00:02:36,990 --> 00:02:40,590
We'll start by modifying the request to the database.
44
00:02:40,590 --> 00:02:43,710
We made that request inside the store file.
45
00:02:43,710 --> 00:02:45,720
We'll scroll to the register.
46
00:02:45,720 --> 00:02:46,470
Action.
47
00:02:48,990 --> 00:02:51,160
There are two steps we'll need to make.
48
00:02:51,180 --> 00:02:56,600
Firstly, we'll need to retrieve the ID generated by the authentication service.
49
00:02:56,610 --> 00:03:03,600
Secondly, we'll update the request to store the user's ID in the resource section of this lecture,
50
00:03:03,600 --> 00:03:07,380
I provide a link to the function we used for creating the user.
51
00:03:08,830 --> 00:03:12,850
The documentation will help us with finding the information we need.
52
00:03:12,880 --> 00:03:16,690
We already know that the function returns the user's credentials.
53
00:03:16,720 --> 00:03:21,140
If we scroll down, we'll come across a section of what will be returned.
54
00:03:21,160 --> 00:03:24,070
It's an object called user credential.
55
00:03:24,100 --> 00:03:28,030
Let's click on the link to find out more about the returned object.
56
00:03:30,330 --> 00:03:35,180
It'll tell us that the object user credential will have four properties.
57
00:03:35,190 --> 00:03:37,990
The one we care about is the user property.
58
00:03:38,010 --> 00:03:41,010
We'll click on the link again for more information.
59
00:03:43,190 --> 00:03:46,520
This page is where we'll find the information we'll need.
60
00:03:46,550 --> 00:03:52,460
The user object comes with properties for reading and interacting with the user in the service.
61
00:03:52,460 --> 00:03:56,930
Under the list of properties, the one will need is called UUID.
62
00:03:56,960 --> 00:03:59,690
If we click on it, it'll tell us the following.
63
00:03:59,690 --> 00:04:01,640
The user's unique ID.
64
00:04:01,850 --> 00:04:04,760
This property is exactly what we're looking for.
65
00:04:04,790 --> 00:04:09,990
To be clear, this is the ID assigned to the user in the authentication service.
66
00:04:10,010 --> 00:04:12,790
We're going to save this ID in the database.
67
00:04:12,800 --> 00:04:14,690
Let's switch back to the editor.
68
00:04:14,900 --> 00:04:19,040
We'll be working in the register action for the first request.
69
00:04:19,040 --> 00:04:22,910
We're going to assign the functions return value to a variable.
70
00:04:22,940 --> 00:04:26,300
The variable will be called user credentials.
71
00:04:28,530 --> 00:04:30,210
We're finished with step one.
72
00:04:30,240 --> 00:04:35,040
The second step is to update the request to the database to use the ID.
73
00:04:35,070 --> 00:04:40,290
Firebase has two functions for inserting the data into the collection we're using.
74
00:04:40,290 --> 00:04:41,160
The first one.
75
00:04:41,160 --> 00:04:46,710
The ADD function will insert a document into a collection with the generated ID.
76
00:04:46,740 --> 00:04:49,800
It doesn't allow you to generate an ID or self.
77
00:04:49,800 --> 00:04:54,240
If you'd like to use a custom ID then you'll need to use the other function.
78
00:04:54,750 --> 00:04:57,480
The second function is called set.
79
00:04:57,510 --> 00:05:02,790
We aren't able to use the set function because it's not available through the collection.
80
00:05:02,790 --> 00:05:07,230
If we'd like to use the set function, we'll need to select a document.
81
00:05:07,230 --> 00:05:14,250
First, let's look at what the code looks like and then I'll explain in the second request before we
82
00:05:14,250 --> 00:05:18,150
call the ADD function chain a function called document.
83
00:05:20,660 --> 00:05:25,820
The document function allows you to select a document in a collection.
84
00:05:25,940 --> 00:05:31,230
However, the document does not exist because we're trying to edit to the database.
85
00:05:31,250 --> 00:05:32,640
That's perfectly fine.
86
00:05:32,660 --> 00:05:37,170
The document function will create the document if it doesn't exist.
87
00:05:37,190 --> 00:05:41,710
This function gives us the opportunity to assign an ID to the document.
88
00:05:41,720 --> 00:05:48,140
It has one argument which is the name of the ID we'll pass in the following user credentials.
89
00:05:48,140 --> 00:05:50,900
Dot user dot uid.
90
00:05:53,040 --> 00:05:56,880
Firebase will store the document with the ID we passed in.
91
00:05:56,880 --> 00:05:59,900
The ID is not the only thing we'll want to change.
92
00:05:59,910 --> 00:06:02,910
The document function returns the document.
93
00:06:03,120 --> 00:06:09,480
The object does not come with a function called AD and said we need to change this to set.
94
00:06:11,700 --> 00:06:16,640
The set function will add or modify existing properties in a document.
95
00:06:16,650 --> 00:06:20,040
The argument is an object of changes we'd like to make.
96
00:06:20,040 --> 00:06:23,760
We don't need to make any changes to the object being passed in.
97
00:06:23,760 --> 00:06:25,230
This will still work.
98
00:06:25,560 --> 00:06:29,370
Before we test things, I want to perform one more task.
99
00:06:29,370 --> 00:06:31,530
I haven't been completely honest.
100
00:06:31,530 --> 00:06:36,990
The authentication service can store additional information about the user, but it's limited.
101
00:06:37,020 --> 00:06:39,930
Every user registered comes with a pro file.
102
00:06:39,930 --> 00:06:45,870
There are two things you can store in the profile a display name and a profile image.
103
00:06:45,870 --> 00:06:50,220
We'll store the display name in the service, for example purposes.
104
00:06:50,250 --> 00:06:55,770
After storing the user in the collection, we'll call a function called user credentials.
105
00:06:55,770 --> 00:06:58,650
Dot User dot update profile.
106
00:07:00,930 --> 00:07:02,750
It has one argument.
107
00:07:02,760 --> 00:07:04,320
It's an object of properties.
108
00:07:04,320 --> 00:07:06,430
We'd like to update on the profile.
109
00:07:06,450 --> 00:07:12,360
There are two properties we can update on the profile, the display name and profile image.
110
00:07:12,360 --> 00:07:17,460
We won't have a profile image, so we'll set the display name property.
111
00:07:22,550 --> 00:07:24,520
This task is asynchronous.
112
00:07:24,530 --> 00:07:28,910
We'll add the await keyword before it to wait for the response.
113
00:07:31,080 --> 00:07:32,880
Let's give things a test.
114
00:07:41,370 --> 00:07:44,300
On my end, I'll receive a success message.
115
00:07:44,310 --> 00:07:48,150
If I were to inspect the console, I wouldn't find any errors.
116
00:07:48,180 --> 00:07:49,310
Fantastic.
117
00:07:49,320 --> 00:07:51,680
Let's verify things in Firebase.
118
00:07:51,690 --> 00:07:54,330
Navigate to the authenticated section.
119
00:07:56,650 --> 00:08:03,460
In the authenticated section, we'll find the newly created user take note of the ID assigned to the
120
00:08:03,460 --> 00:08:04,150
user.
121
00:08:04,180 --> 00:08:08,050
It should match the ID assigned to the document in the database.
122
00:08:08,080 --> 00:08:11,530
Let's switch over to the database to check if that's true.
123
00:08:13,800 --> 00:08:16,310
Plainly enough, the IDs match.
124
00:08:16,320 --> 00:08:18,630
Everything works like we wanted it to.
125
00:08:18,660 --> 00:08:24,270
We've successfully connected the user's data in the database to their authenticated account.
11790
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.