FRANK VAN PUFFELEN: Do you already
do a hashtag AskFirebase or no?
JEN PERSON: No, I am killing the hashtag.
FRANK VAN PUFFELEN: I'm really confused about this.
JEN PERSON: Because it's not 2012 anymore.
[MUSIC PLAYING]
Hey, everyone.
Welcome to another episode of "Ask Firebase".
I'm your host, Jen Person.
And today, I'm joined by Frank van Puffelen.
So welcome back.
I'm so glad to have you here.
And you're going to help me answer some Firebase questions.
FRANK VAN PUFFELEN: Definitely.
It was so much fun last time that I
can't wait to see what questions you have for us this time.
JEN PERSON: Great.
So let's just get right into it then.
Our first question here comes from Sumit Kumar on Twitter.
And he says, how can I test my Cloud functions
with database, auth, and storage triggers locally
before deploying them?
FRANK VAN PUFFELEN: That's a great question.
We now actually have a shell.
And you can emulate essentially any Cloud function locally.
So you just run it locally, and you invoke it with the data
that you want.
So you can use it for quickly testing or also throwing
some weird data at it that you might not easily
get in real life, but you still want your code to handle it.
JEN PERSON: Yeah, that's huge.
I'm really excited about this.
It's really nice.
Sometimes I enjoyed having those couple minutes
where you deploy and you can just go get yourself a snack
while you're waiting.
FRANK VAN PUFFELEN: No, I'm always
drinking way too much coffee when that happens, so no.
Definitely.
JEN PERSON: So it's nice.
Yes, you can test them locally now.
We'll throw a link in the documentation
so you can check out how to do that.
Great.
Cool.
Yeah, that's a definitely heavily-requested feature.
FRANK VAN PUFFELEN: Yeah.
No, we are very glad that it's out in '18.
JEN PERSON: All right.
Let's see what else we got here.
Also from Twitter, where we get lots of great questions, Emery
Owner says, can I send email with Firebase functions,
like, let's say, a newsletter?
FRANK VAN PUFFELEN: Oh, yes, definitely.
It's one of the--
JEN PERSON: I love this sample.
FRANK VAN PUFFELEN: Yeah, it's one of the common use cases,
actually.
We have it on our documentation, but that doesn't
mean it's not a good question.
So you would set up, essentially-- in somewhere
like your Firebase database or Firestore,
you keep a list of the users that you
want to send the newsletter to.
So if they've subscribed--
and then you set up a function that you trigger periodically.
And do you know how to do that?
JEN PERSON: Why, yes, I do.
So one of the ways that you can do it--
I actually made a video about it.
So we'll throw that link in there as well.
But you can set up a cron job using
an HTTP-triggered function.
And then you can just--
however much you want to trigger that-- once a week,
once a day--
it would just call that function and send out the email.
There are email services that you can choose to use for that.
It really depends on what your use case is.
But yeah, again, we have a great sample for that.
So check it out.
All right.
Let's check out this next question.
[? Aydeep ?] Patel says, I would love
to see a series for server side code.
I think this is a very important point for any application.
FRANK VAN PUFFELEN: Yeah, for sure.
No, it is.
With Firebase, we try to make sure
that you can focus on client side code as much as possible.
But there's always a few cases where you really
can't run things on the client.
And then you need server side codes.
That's why we're so happy that we now
have Cloud functions available, as you
know very well, because you did some great series on it.
JEN PERSON: Yeah.
And I'm going to be doing even more, specifically looking
at the Firebase Admin SDK.
So this can be used in conjunction
with Cloud functions.
But it's also an option for other kind of server side code,
if you choose not to use Cloud functions,
because you might have situations where
instead of just having something that you want triggered when
a certain action occurs, you want something
that can run all the time.
So I'll be looking into those.
But as I start making these videos,
I would love to hear more Ask Firebase
questions around what sort of server side questions you have.
FRANK VAN PUFFELEN: So this is where you all come in.
So if you have a question about, how
would I do this with some server side versus client side codes,
or how would you actually implement something
on the server with the Admin SDK,
put the question on Twitter, on Stack Overflow,
and tag it with AskFirebase and Jen might get to it.
JEN PERSON: Yeah, absolutely.
Without your questions, I can't have this show.
So got to send them my way.
FRANK VAN PUFFELEN: Ooh, the next one I'm going to read.
It's from [? Jabar ?] Asadi.
And his question is, what's the difference between Google Cloud
Messaging and Firebase Cloud Messaging?
And I think you might know that one.
JEN PERSON: Yeah, I'll definitely take this one.
So Firebase Cloud Messaging is the latest, most up-to-date
version of Google Cloud Messaging.
And we have some great large-scale clients that
use Google Cloud Messaging.
We send billions of messages a day.
I had to look up that number again.
I just couldn't believe it.
So Firebase Cloud Messaging, being the latest service,
offers a few different features that
have built upon this great foundation of Google Cloud
Messaging.
So let's see.
A couple of things that you can do
is you can subscribe users to specific topics.
And you can send messages targeted
by different combinations of those.
So maybe you want to send a message
to users who are subscribed to two different topics
or subscribe to one and not to another one.
So you have different options that you
can have to put together.
So it's really customizable.
So you're not spamming all of your users.
You're really targeting them.
FRANK VAN PUFFELEN: That's pretty cool, actually.
JEN PERSON: Yeah.
FRANK VAN PUFFELEN: I also heard that there was something
recently released called platform overrides.
Can you tell me more about that?
JEN PERSON: Yeah, this was a huge push.
And I'm really glad that we have it,
because as you probably know, as developers,
the different platforms-- web and iOS and Android--
have slightly different ways of doing messaging.
So what that means is, it was a challenge
to send a similar-looking message
to your different platforms.
You actually had to even have-- let's
say you had a topic for a specific sport.
You'd have to have that topic for the iOS app and Android app
if you wanted to be able to have them, let's say,
select that message and go to a specific spot in your app.
But now with platform overrides, you can send one message,
and it has options to send, depending on what platform
your users are on.
So you can just have a single topic.
And it allows you to much easier and more quickly
target those users.
FRANK VAN PUFFELEN: That's very cool.
So that means that you could have a single message
that you send to users, both on iOS and Android,
and it behaves as they would expect on each of the platforms
then.
JEN PERSON: Exactly.
FRANK VAN PUFFELEN: Ooh, that's nice.
I hope that actually answers your question, [? Jabar. ?]
JEN PERSON: All right.
Let's see if we got any other ones.
Abdullah on Twitter says, how do I use auth.phoneNumber
in Firebase security rules?
So let's say you want to make sure
that to access a specific piece of data,
they are the user that was signed
in-- so sort of how we use security
rules for other things.
FRANK VAN PUFFELEN: Yeah.
No, definitely.
It's a good question.
Actually, I think it's so good that I think I already answered
this one on Stack Overflow.
JEN PERSON: Yeah.
FRANK VAN PUFFELEN: So I have a full example there.
But the phone number of a user that
has authenticated with the phone number
is available in your security rules.
So you can, in your security rules,
find it under Auth.token.phoneNumber.
And then you can actually use that phone number everywhere.
As usual, same as with other forms of authentication,
I recommend that you mostly try to stick to using the user ID--
the UID--
in your rules to secure.
And then do a look-up of the phone number where needed.
But if you want to secure it directly on the phone number,
it's available in auth.token.phoneNumber.
JEN PERSON: Yeah, that's a really good point,
because with the UID then, no matter how
your users are signing in, you have a consistent method
of security rules.
FRANK VAN PUFFELEN: Exactly.
Imagine that a user first signs in with a phone number
and then later they sign in with a Facebook
provide, for example.
Then actually, your phone number security rule
won't work anymore.
But the UID of that user will still be the same.
JEN PERSON: Well, thanks, everyone,
for watching another episode of "Ask Firebase."
And thank you so much, Puf, for coming on the show
and helping me answer some questions.
FRANK VAN PUFFELEN: It was my pleasure.
JEN PERSON: Yeah.
Be sure to stay tuned for future episodes
to see some great Firebase questions answered.
And if you have a great question, make sure
you hit us up on social media with the hashtag AskFirebase,
and maybe you'll see it on a future episode.
FRANK VAN PUFFELEN: Yeah.
Remember, everyone, keep asking questions.
It's the only way we can make shows like this.
Thanks for joining.
[MUSIC PLAYING]
[INAUDIBLE] Jen.
JEN PERSON: What?
FRANK VAN PUFFELEN: I'm [INAUDIBLE] the light bulb.
[INAUDIBLE]