React devs might find this archived course helpful to reference, but this course has been updated! We now recommend you take the Firebase Fundamentals course.
Transcript from the "Getting User Document Data" Lesson
>> Steve Kinney: I'm gonna go back to this one a second, but first I'm also gonna give me the opposite here, which is
>> Steve Kinney: This will also be an interesting function, this will be the ability to go get one out of the database. And I'll show you why I'm doing this in a second.
>> Steve Kinney: So that will take a uid, and if for some reason it's not given a uid, just return null, otherwise
>> Steve Kinney: Let's try to get it out of the database
>> Steve Kinney: So this is very similar to what we're doing with getting a Post before, Firestore, this time the collection would be users.
>> Steve Kinney: And the doc will be that uid, now you could also do the doc users/uid, both are fine, I'm mostly switching to show you that both work. And we'll get it, and so we should have that and with that, we will return. A lot of the previous ones had the uid in that object, that's our key.
[00:01:25] So we want to combine the key with the value, much like we were doing with the Posts earlier. So we'll say, uid, and then we'll say all the other userDocument.data.
>> Steve Kinney: Cool, and if that doesn't work, tell us about it in the console, don't ever tell our users that something didn't work.
>> Steve Kinney: Error fetching the user, let's give me the error.message, we'll do that up there as well, I don't need the full thing.
>> Steve Kinney: All right, one of the thing which is just a convenience that I'm gonna do, is
>> Steve Kinney: I'm gonna go ahead and
>> Steve Kinney: I'm gonna get it after I create it, mostly cuz otherwise I would have to create it and then go get it somewhere else.
[00:02:22] So I'm gonna have this method return
>> Steve Kinney: That user, okay, that was a lot of code, we hope it works, we hope I didn't make any boo-boos. None of you saw any boo-boos, so it's like we're all complicit if I made a typo, so that's good, I don't have to feel embarrassed.
[00:02:42] So you have the ability to conditionally create one, and then we go and get it, right? That is arguably, if that stressed you out at all, that is the most complicated Firestore query that we're gonna write today. So you survived, hoping that it works, so we need to do it in two places as we talked about before.
[00:03:04] We need to set this if they submit a form. And we also need to do it on the off State changed, that way if they log in from the Google sign-in.