SPEAKER: What kind of coffees have you had today?
DAVID EAST: I haven't really had that much.
I woke up, and I had a cold brew.
And then I came into work, and then I had a macchiato.
Well no, that's not true.
I actually went back before work,
and I picked up a pumpkin latte, because, you know,
it's September.
Right before lunch, I had my pre-lunch mocha.
And then after lunch, I had my post-lunch mocha.
And then we were filming Ask Firebase,
so I had my pre Ask Firebase triple shot, venti, Americano,
non-whip mocha-- so not that much coffee.
[MUSIC PLAYING]
What's up, everybody?
Welcome back to a brand new episode of #AskFirebase,
the show where you send your questions
in on YouTube, Twitter, Stack Overflow, and we answer them.
My name is David East.
I'm the Developer Advocate here at Google on the Firebase team.
In case you didn't know, we are having our largest
ever Firebase Developer summit this November 7 in Berlin.
And we want you to participate.
So we're going to have lots of members of the Firebase team
there.
And we have some really exciting product updates.
So you definitely want to check that out.
And we have a link in the description for more.
So the first question comes from Samir
who asked, on YouTube-- what are some
of the differences between AngularFire for Angular 1
and AngularFire for Angular 2?
And you know what, Samir?
That is a great question.
So when we set out to build each one of these libraries,
we design them for the framework.
So for AngularFire 1, we tightly integrated
Firebase into the two-way data binding system.
The two-way data binding system is-- is every single time
your model updates, your view updates.
Or if your view updates, your model updates.
And we created a third part of that where every time
you update something, it goes all the way back
to your database.
We call that three-way data binding.
So with Angular 2, they have an observable system,
which allows you to model your data
flow before any data is actually downloaded to your web page.
And what we've done is we've taken the Firebase database,
and we've taken the real time data streams,
and we've built them into these observables, which
make it really easy to bind data from your database right
to your view.
And you can see it just update in real time.
So, Samir, the differences are is, for Angular 1,
we tightly integrated into the two-way data binding system.
And for Angular 2, we're tightly integrated
into the observable system.
Great question.
So this next question comes from Daniel on Twitter.
And Daniel asked-- will you be putting together
any sort of angularfire2 seed repo?
Because it would be great to be able to see everything working
together and all the best practises.
Well, Daniel, we are actually working
on just something like that.
[SLURP] So right now we're preparing a bunch of recipes
so you can see, like-- how do I check for existing data?
How do I combine multiple observable streams together?
All these things that you want to know
how to do with AngularFire 2, we're
going to have an entire repo for.
And right now, if you go to the install and set-up directions,
you can get started with Angular 2
and AngularFire 2 in really just a matter of minutes.
So you should go check that out.
And the link is in the description.
Great question.
Chad on Twitter asked-- I would loved
to see an example of saving and retrieving multiple users'
data using Firebase and Angular 2.
Thanks, #AskFirebase.
No.
Thank you, Chad.
So AngularFire 2's dynamic querying
makes this really easy.
The first thing that you always do
when you're using AngularFire is that you inject the AngularFire
service into your component's constructor.
And once you've done that, you can do things
like create a Firebase list observable.
And this is how you retrieve a list of data from our real time
database.
And so to do that, we can say af.database.list.
And at this point, we need to provide where
the data is actually located.
And the path for our users would probably
be underneath the user's location.
And so this list observable is a list of users in our database.
So if we want to be able to add new users,
we can just say the observable stream.push.
And it's just like adding items onto an array.
So now when we create this Firebase list observable,
we are retrieving all of the users in the database.
And if we want to just get a subset of that back,
we can use the dynamic querying capability of AngularFire 2.
The second parameter of the Firebase list observable
allows us to specify our query.
So we provide an object, and then we specify our query.
But let's say we only wanted to get back the users who
are located in Washington DC.
Well we can say we want to order by the child of location.
And we can make sure that's equal to DC.
That's just an equivalence query.
But we can even do a range query.
So we can say that we only want to order
by the age of our users.
And we can start at the age of 18.
And we can end at 45.
So if you want to learn more about AngularFire
2 and the Firebase list observable,
make sure to check out the docs, which are in GitHub.
And the link is in the description.
Great question, Chad.
[MUSIC PLAYING]
[SLURP] This next question is-- how can I
prevent the duplication of user data
when a user signs up with the same email address
more than once?
And that's a really good question,
because you don't want the same user
signing up over and over again.
That would make your system super confusing.
How you solve that is by keying off of the user's email address
and then making sure that the user can't
save to the same spot more than once with security rules.
So if you take a look at this little bit of security rules
right here, you can see that I save my users
underneath a user's node.
And then I'm using the "$email" wild card to signify that
I'm keying off of the email.
And then I'm saying only the people who
can write to this location are authenticated users.
And the kicker right here is that no data
exists at this path.
So if a user has already signed up with the same email,
data will exist and this rule won't allow them to sign up.
If you want to make sure that you aren't duplicating user
data, make sure that you're keying off
with something unique, and you're
writing that your security rule isn't allowing the same data
to be written twice.
And if you want to know more about that,
we have an entire documentation section
on securing user data using security rules.
You should check that out with the link in the description
below.
Great question.
[MUSIC PLAYING]
Ah!
Next question!
What's the difference between the Firebase authentication
methods, createUserWithEmailAndPassword,
and signInUserWithEm ailAndPassword()?
Well, while these methods might seem different,
there is a little similarity between the two of them.
So signInUserWithEmailAndPassword()
pretty much does what you think it does.
You sign-in a user provided that they give you
an email and a password.
But now createUserWithEm ailAndPassword(),
it will create a user when they give you an email
and a password, but it will also sign them in.
So it's really important to know that when
you are using that method, because you
have to know that it's going to automatically sign in the user
after you've created them.
And if you want to learn more about this,
I did an entire video on email and password authentication
with Firebase.
And you can check that out with the link in the description
below.
Great question.
[MUSIC PLAYING]
Ah! [CLAP] Next question!
SPEAKER: No more questions, Dave.
DAVID EAST: Do we have any more coffee?
SPEAKER: You drank it all.
DAVID EAST: No!
So that's all of the coffee and questions for the day.
Thank you all so much for sending them in.
And if you want to see your question answered,
make sure to tweet at us, go on to YouTube, Stack Overflow,
and just use the #AskFirebase, and we'll
keep on answering them.
If you enjoyed this video, make sure to like and subscribe
so you can stay up to date with all the latest and greatest
Firebase content.
That's all for today.
I'm going to go look for some more coffee.
[MUSIC PLAYING]