All language subtitles for 106 Storing User Data In Our App.en_US

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish Download
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,190 --> 00:00:09,320 Now, inside of our jails, we're calling that new create user profile document function that we just 2 00:00:09,320 --> 00:00:09,620 made. 3 00:00:10,640 --> 00:00:17,030 What we want to do is we want to make sure that we also. 4 00:00:18,040 --> 00:00:22,480 Call our set state with current user, with the actual object itself. 5 00:00:23,420 --> 00:00:30,860 So what we'll do here is we will modify our code to make sure that we understand what's actually happening. 6 00:00:31,950 --> 00:00:36,870 So first, let's change the user to user off, because now we know what we're getting back is a user 7 00:00:36,870 --> 00:00:43,920 off and we'll say if the user off object is not null, meaning if it exists, right. 8 00:00:44,070 --> 00:00:49,470 We remember that user could be no more signing up and we don't want to set anything here. 9 00:00:49,470 --> 00:00:49,830 Right. 10 00:00:49,860 --> 00:00:51,390 If it's if we're signing up. 11 00:00:53,150 --> 00:00:56,900 We remember what we get back from our function. 12 00:00:57,850 --> 00:01:05,640 Is the user ref, we made sure that we were passing back the user riff raff object, right? 13 00:01:06,640 --> 00:01:07,480 Right here at the end. 14 00:01:08,560 --> 00:01:19,060 We want it because we're going to use it to check if our database has updated at that reference with 15 00:01:19,060 --> 00:01:19,900 any new data. 16 00:01:21,350 --> 00:01:26,630 Very similar to our on off state change, we're kind of seeing if the snapshot has changed. 17 00:01:28,110 --> 00:01:34,640 But chances are it won't have because we are not going to update the user ever inside of our code, 18 00:01:35,250 --> 00:01:41,820 but the process of what this method will do, which I'll show you in a second, is that the moment it 19 00:01:41,820 --> 00:01:49,260 instantiates, meaning that the moment our code runs it, it will still send us a snapshot object representing 20 00:01:49,260 --> 00:01:52,460 the data that is currently stored in our database. 21 00:01:53,400 --> 00:01:55,560 And that method is on snapshot. 22 00:01:56,190 --> 00:01:59,610 Calling on snapshot is very similar to calling on Off-stage changed. 23 00:02:00,590 --> 00:02:09,110 And what we get back is the snapshot object and on the snapshot object is where we're going to get the 24 00:02:09,110 --> 00:02:13,670 data related to this user that we just possibly stored. 25 00:02:13,670 --> 00:02:14,030 Right. 26 00:02:14,030 --> 00:02:20,840 If it was a new authentication or the data related to the user that is already stored in our database. 27 00:02:23,450 --> 00:02:25,130 Let's talk about these snapshot objects. 28 00:02:26,630 --> 00:02:31,970 A document snapshot object is one that, of course, we get from our document reference object, right, 29 00:02:31,970 --> 00:02:33,830 using the doGet method, as we saw. 30 00:02:35,000 --> 00:02:41,780 It allows us to check if the document exists, as we know, but it also allows us to get properties 31 00:02:42,530 --> 00:02:45,890 of that data using the DOT data method. 32 00:02:47,370 --> 00:02:54,120 We actually do not get any data until we use the data method, so I'll show you. 33 00:02:55,030 --> 00:02:57,690 If right now I simply can't so log my snapshot. 34 00:03:00,110 --> 00:03:01,410 Here we get our snapshot. 35 00:03:01,940 --> 00:03:08,120 You see that it has the exists, it has the it, but it doesn't have any of the properties we have to 36 00:03:08,120 --> 00:03:12,500 call data in order to actually see what our data looks like. 37 00:03:13,250 --> 00:03:18,710 And it'll come back to us as an object with those properties inside of our database. 38 00:03:18,860 --> 00:03:19,160 Right. 39 00:03:19,220 --> 00:03:23,750 So the display name email, the created out, of course, are the properties that we use to store in 40 00:03:23,750 --> 00:03:23,990 here. 41 00:03:25,930 --> 00:03:33,460 So this is the main thing that we need to use, but we see that we don't have the ID now if you remember 42 00:03:33,460 --> 00:03:39,070 on the snapshot itself was the idea of where we currently are in our user rough. 43 00:03:39,100 --> 00:03:43,340 Right, as well as the ID that represents the data of our snapshot right here. 44 00:03:43,930 --> 00:03:51,370 So we need to use these two things combined and call our set state of our current user right here. 45 00:03:52,390 --> 00:03:57,520 And what we're going to do is we're just going to call set stay here, passing in an object. 46 00:03:58,470 --> 00:04:00,180 With our current user value. 47 00:04:01,940 --> 00:04:05,630 Going to the idea of our snapshot. 48 00:04:07,000 --> 00:04:07,510 EDD. 49 00:04:08,820 --> 00:04:15,660 And then we're going to spread in snapshot data, right, because we get back the object representing 50 00:04:15,660 --> 00:04:20,610 the values, so we're just creating a new object that has both all of the properties of our snapshot 51 00:04:20,610 --> 00:04:23,640 that we want, as well as the idea that we want. 52 00:04:25,690 --> 00:04:31,810 And then just to make sure we're getting everything right, let's just console log this dot state, 53 00:04:32,470 --> 00:04:34,900 right, just to make sure that we're getting this through. 54 00:04:36,280 --> 00:04:38,500 Now, outside of this function. 55 00:04:39,750 --> 00:04:45,360 Outside of this function call where we're checking whether or not the user off exists. 56 00:04:46,380 --> 00:04:56,400 We also want to make sure that our app is aware if the user auth is null, meaning if the user signs 57 00:04:56,400 --> 00:04:59,380 out, we still want to set current user to nothing as well. 58 00:05:00,180 --> 00:05:08,120 So if the user off object comes back and it's null, then what we want to do after this is called this 59 00:05:08,130 --> 00:05:09,090 dot set state. 60 00:05:11,130 --> 00:05:17,610 Where current user goes to our user off, which we know is not right, so this is equivalent to saying 61 00:05:17,760 --> 00:05:19,200 current user to know. 62 00:05:21,040 --> 00:05:28,450 So now what will happen is if a user signs in, right, we'll check if they're actually signing in because 63 00:05:28,450 --> 00:05:29,610 we'll see if there's a user off. 64 00:05:29,770 --> 00:05:37,810 So if there is, we will get back the user ref from our create user profile document method from the 65 00:05:37,810 --> 00:05:39,580 user auth object being passed in. 66 00:05:40,480 --> 00:05:45,510 If there was a document there, we will simply just get back to user. 67 00:05:45,520 --> 00:05:55,720 If if there is no document there, we will create a new object and document right in that place and 68 00:05:55,720 --> 00:05:59,920 we'll still get back the user f and then we're going to subscribe. 69 00:05:59,920 --> 00:06:07,420 Meaning we're going to listen to this user ref for any changes to that data, but will also get back 70 00:06:07,630 --> 00:06:10,540 the first state of that data. 71 00:06:12,040 --> 00:06:18,580 So then using that, we are going to set the state of our local abcess with the snapshot ID and the 72 00:06:18,580 --> 00:06:25,360 snapshots data, and then if the user ever logs out, we'll make sure to set the current user to know. 73 00:06:25,390 --> 00:06:28,860 Right, setting it to the null that will get back from the library. 74 00:06:29,740 --> 00:06:32,320 And now that we have all of this, let's actually see what happens. 75 00:06:33,790 --> 00:06:35,540 We made a mistake with our console log. 76 00:06:36,160 --> 00:06:44,500 So if you remember, our console log can't go after substate state because set state is a synchronous 77 00:06:45,070 --> 00:06:51,220 meaning that there's a chance that when we call it sets, it is not actually finished being called. 78 00:06:51,940 --> 00:06:55,150 The only way for us to make sure that set state is fully called. 79 00:06:55,150 --> 00:06:58,900 And then we're able to see what the state of it is, is. 80 00:06:58,900 --> 00:07:04,630 We pass a second function, right, as a parameter in such state as the second parameter. 81 00:07:05,800 --> 00:07:11,740 Where we do the actual logging and sets that will then call our function after a state as fully propagated. 82 00:07:12,520 --> 00:07:15,220 So now we see that we're actually storing our current user. 83 00:07:16,520 --> 00:07:21,470 And this is actually all of the data that we got from our database as well as the created that sign 84 00:07:21,470 --> 00:07:22,560 and the ID. 85 00:07:24,380 --> 00:07:26,790 So hopefully this was not too overwhelming. 86 00:07:27,110 --> 00:07:30,860 I know that this is a lot of new code that we just covered. 87 00:07:31,820 --> 00:07:38,000 And it's definitely a lot of code that we haven't seen before, all related to the fire store, fire 88 00:07:38,000 --> 00:07:38,690 base library. 89 00:07:39,870 --> 00:07:46,020 We've also mixed and matched the off and the fire story library code together to create these new objects 90 00:07:46,020 --> 00:07:49,660 inside of our database and then bring them back in and then store them. 91 00:07:49,680 --> 00:07:50,880 There's a lot of back and forth. 92 00:07:51,510 --> 00:07:55,380 I know it's a lot of confusing code, but also a confusing flow. 93 00:07:56,430 --> 00:08:03,420 But I promise you, the more you practice with both these Raef objects and the snapshot objects, the 94 00:08:03,420 --> 00:08:06,540 better you'll understand the purpose of what each is for. 95 00:08:07,580 --> 00:08:11,780 And this is actually pretty much the core of how we use the Firestone Library. 96 00:08:11,810 --> 00:08:18,110 It's actually really simple once you've mastered and understood these concepts that we've just covered. 97 00:08:19,670 --> 00:08:25,580 Now, let's get rid of this, because we don't need this anymore, and we'll work on our sign up next. 98 00:08:25,580 --> 00:08:27,980 Right, which is more with our auth library. 99 00:08:28,610 --> 00:08:36,650 But now that we've done this flow inside of our APGAR'S, if we add our sign up with email and password 100 00:08:36,650 --> 00:08:42,620 write, this code is all still going to work the exact same because we've compartmentalized our actual 101 00:08:42,620 --> 00:08:48,200 storage and our actual sextape separately from our authentication. 102 00:08:48,740 --> 00:08:54,620 And that'll make more sense once we actually start writing the sign up, but definitely rewash these 103 00:08:54,620 --> 00:08:55,730 last few videos. 104 00:08:55,730 --> 00:09:02,510 If you feel confused about Firebase, it's incredibly powerful and it does have a bit of a learning 105 00:09:02,510 --> 00:09:04,370 curve to get used to how to use it. 106 00:09:05,300 --> 00:09:12,950 But it's very valuable because this is actually way, way easier than any other way of spinning up our 107 00:09:12,980 --> 00:09:16,190 own backend server and authentication service. 108 00:09:17,160 --> 00:09:19,050 So let's tackle sign up next. 11066

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.