Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,120 --> 00:00:02,490
We're finished with the registration form.
2
00:00:02,490 --> 00:00:05,250
The next thing to tackle is the login form.
3
00:00:05,280 --> 00:00:08,220
A lot of what we'll be doing is the same as before.
4
00:00:08,250 --> 00:00:12,650
Unlike last time, I won't draw this out into about a dozen lectures.
5
00:00:12,660 --> 00:00:14,850
We'll fly right by this.
6
00:00:14,910 --> 00:00:18,240
We'll start by opening the login form component.
7
00:00:20,210 --> 00:00:26,060
As you may recall, we separated the forms into separate components for easier management.
8
00:00:26,090 --> 00:00:30,640
In the previous section we've taken care of validating the login form.
9
00:00:30,650 --> 00:00:35,210
The next thing to take care of is to send the login data to Firebase.
10
00:00:35,390 --> 00:00:39,440
The logic for performing a login will be outsourced into an action.
11
00:00:39,440 --> 00:00:42,970
From this component, we are going to run the action function.
12
00:00:42,980 --> 00:00:48,260
Let's prepare the component before defining the action function at the top of the script.
13
00:00:48,260 --> 00:00:48,890
BLOCK.
14
00:00:48,920 --> 00:00:50,330
Import the map.
15
00:00:50,330 --> 00:00:53,210
Actions function from the package.
16
00:00:55,290 --> 00:01:00,420
Next import the user store with a name called Use User Store.
17
00:01:02,520 --> 00:01:05,160
Let's map a function called authenticate.
18
00:01:05,190 --> 00:01:08,520
This function doesn't exist, but that's perfectly fine.
19
00:01:08,520 --> 00:01:11,220
We're just trying to prepare the component.
20
00:01:11,220 --> 00:01:16,650
After preparing the components, we'll define this function inside the methods object.
21
00:01:16,650 --> 00:01:17,700
Run the map.
22
00:01:17,700 --> 00:01:20,610
Actions function with the spread operator.
23
00:01:22,840 --> 00:01:24,670
Passing the user store.
24
00:01:26,660 --> 00:01:30,620
Lastly in an array, add the authenticate function.
25
00:01:34,140 --> 00:01:37,700
We can call this function from within the login method.
26
00:01:37,710 --> 00:01:44,820
After updating the alert message, let's call the this dot authenticate function with the values argument.
27
00:01:46,860 --> 00:01:52,620
The values argument is where we're keeping the email and password input values.
28
00:01:52,650 --> 00:01:57,840
This argument is provided by the V form component when the form is submitted.
29
00:01:57,870 --> 00:01:59,160
One last thing.
30
00:01:59,160 --> 00:02:03,270
We'll add the await keyword before dispatching the action.
31
00:02:05,730 --> 00:02:07,230
The action we're going to write.
32
00:02:07,230 --> 00:02:08,960
We'll have a synchronous code.
33
00:02:08,970 --> 00:02:11,790
We want to wait until the action is complete.
34
00:02:12,360 --> 00:02:18,750
Make sure the async keyword is added before the name of the function, just in case we're going to wrap
35
00:02:18,750 --> 00:02:21,390
the dispatch with a try and catch block.
36
00:02:25,110 --> 00:02:28,020
If an error occurs, we'll want to handle it.
37
00:02:28,020 --> 00:02:34,500
Inside the catch statement, we're going to update the login and submission data property to false.
38
00:02:36,760 --> 00:02:42,010
Will update the login alert variant property to BG Read 500.
39
00:02:44,420 --> 00:02:49,820
Lastly, we're going to update the log and alert message property to the following message.
40
00:02:49,820 --> 00:02:51,860
Invalid Login Details.
41
00:02:54,150 --> 00:02:59,070
Be sure to return the function to stop the function from further execution.
42
00:03:01,370 --> 00:03:05,320
We won't need to make any more changes to the login form component.
43
00:03:05,330 --> 00:03:11,570
We'll next move on to the store file to define the action inside the actions object.
44
00:03:11,570 --> 00:03:13,820
Define the authenticate function.
45
00:03:16,120 --> 00:03:22,210
Since we'll be making an asynchronous request to Firebase, the function should have the async keyword
46
00:03:22,210 --> 00:03:23,040
before it.
47
00:03:23,050 --> 00:03:26,260
We are being passed down data from the component.
48
00:03:26,260 --> 00:03:27,870
We'll want to accept it.
49
00:03:27,880 --> 00:03:30,760
Add the values argument to the function.
50
00:03:33,090 --> 00:03:35,150
The function will be straightforward.
51
00:03:35,160 --> 00:03:37,590
There are two tasks will perform.
52
00:03:37,620 --> 00:03:41,740
First, we'll send a request to Firebase with the payload data.
53
00:03:41,760 --> 00:03:48,600
If the request is a success, we'll want to commit a mutation to log the user in the state inside the
54
00:03:48,600 --> 00:03:49,160
action.
55
00:03:49,170 --> 00:03:50,820
Call the function off.
56
00:03:51,210 --> 00:03:53,490
Sign in with email and password.
57
00:03:55,740 --> 00:03:57,670
I'm introducing a new function.
58
00:03:57,690 --> 00:04:00,120
It comes with the authentication object.
59
00:04:00,120 --> 00:04:01,140
We import it.
60
00:04:01,180 --> 00:04:05,460
It'll assign the user into the application with their email and password.
61
00:04:05,490 --> 00:04:09,000
It has two arguments the email and password.
62
00:04:09,030 --> 00:04:11,170
These exist within the payload.
63
00:04:11,190 --> 00:04:15,090
We'll set the arguments to their respective payload values.
64
00:04:17,360 --> 00:04:19,560
This request is asynchronous.
65
00:04:19,579 --> 00:04:23,540
We'll need to add the await keyword before calling the function.
66
00:04:25,830 --> 00:04:32,250
If the function successfully authenticates the user, we can toggle the user logged in state property
67
00:04:32,250 --> 00:04:33,090
to true.
68
00:04:35,370 --> 00:04:37,770
Otherwise the function would throw an error.
69
00:04:37,800 --> 00:04:40,050
The next line of code would never run.
70
00:04:40,410 --> 00:04:41,360
We are done.
71
00:04:41,370 --> 00:04:46,980
We don't have to wrap the asynchronous function with a tri catch block because it'll throw an error.
72
00:04:46,980 --> 00:04:52,680
If the authentication was unsuccessful, errors will stop the function from executing further.
73
00:04:52,710 --> 00:04:54,990
Let's try giving things a test.
74
00:04:57,240 --> 00:05:03,960
Before you do, I recommend clearing the site data to start with a fresh slate in the Chrome Developer
75
00:05:03,960 --> 00:05:04,570
Tools.
76
00:05:04,590 --> 00:05:08,100
Navigate to the application panel on the sidebar.
77
00:05:08,130 --> 00:05:10,830
There will be an option to clear the storage.
78
00:05:10,830 --> 00:05:13,860
Click on the clear site data button.
79
00:05:16,150 --> 00:05:22,780
Once you've got that settled, refresh the page, then try logging in with an account that doesn't exist.
80
00:05:25,880 --> 00:05:27,830
Will receive an error message.
81
00:05:27,830 --> 00:05:34,020
If we look in the console, an error will be logged from the request sent by the Firebase SDK.
82
00:05:34,040 --> 00:05:37,160
In addition, we should check the mutation log.
83
00:05:39,450 --> 00:05:43,890
The action did not commit the mutation because the request threw an error.
84
00:05:43,920 --> 00:05:49,320
Even though we didn't return the function ourselves, the error stopped the function from executing
85
00:05:49,320 --> 00:05:50,010
further.
86
00:05:50,040 --> 00:05:53,250
Now let's try logging in with valid credentials.
87
00:05:55,720 --> 00:05:58,010
We will receive a success message.
88
00:05:58,030 --> 00:06:04,660
If I were to refresh the page, we'd continue to be logged in because Firebase stores the token.
89
00:06:07,020 --> 00:06:10,910
It will take care of verifying if the user is logged in afterward.
90
00:06:10,920 --> 00:06:11,890
That's great.
91
00:06:11,910 --> 00:06:15,880
We've successfully created a login and registration form.
92
00:06:15,900 --> 00:06:19,000
After confirming everything, patting yourself on the back.
93
00:06:19,020 --> 00:06:21,450
We've had to do a lot to get this working.
94
00:06:21,480 --> 00:06:26,070
I know we flew right by this pretty quickly, but this shouldn't be anything new.
95
00:06:26,100 --> 00:06:31,020
Almost everything was the same except for the function for assigning the user in.
96
00:06:31,320 --> 00:06:37,890
In the resource section of this lecture, I provide a link to the sign in with email and password function.
97
00:06:37,920 --> 00:06:41,310
I recommend checking it out if you'd like to learn more about it.
8934
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.