Right, so if you're still here, then congratulations on completing this very basic WhatsApp or I message.
Now, there are a couple of tasks that I would like you to attempt, and they range from quick and easy
to very difficult and might take you a very long time.
Feel free to.
Do you know, the first couple of them?
Definitely.
But after that, totally optional.
If you want to do them, if you do do all of the tasks, then your understanding of this will improve
no end, including if you want to do things for clients, you'll better understand the amount of work
that goes into what you're doing so you can charge the clients accordingly.
That's a big problem I see with new developers.
Right?
Your first task is when you first load the app, it allows you to log in or register.
The problem is in our code we check the user, but no matter what that result is, we immediately set
up Firebase.
At the moment, that's not a problem because we don't have any rules on our database.
We're allowing everyone to read and write to our database.
Obviously, in production, you would never, ever do that.
You would make sure a user is authenticated.
So what you need to do is check the current user is true or false, and then depending on whether it's
true or false, you actually want to then go ahead and set up Firebase, but only do it once.
Because if you have something that checks continuously or checks every time the view loads as it comes
onto the screen or not, that's a view will appear, then this is going to be repeated and you're going
to get more handles, which means every time data changes, it will get added two or three times to
your list.
So you're going to multiply a whole bunch of bugs and problems.
Clearly you don't want that.
So you need to think very carefully about how you go about modifying that.
That's your first task and that's the one I would definitely recommend you actually do.
Do not skip it because it helps train your logical brain for this.
The next task, if you choose to accept, is to define the data that you are sending to Firebase with
a user ID reference.
So in the firebase authentication documentation, it'll tell you each user has a particular user ID.
You can use their ID, you can use their email, whatever it is.
But I want you to do is attach a user's email to the data as it gets stored in Firebase.
There is a way to do that and you can do that on the firebase side, not the app side.
Never do things like that on the app side because any malicious user could add an email address and
then they'd have access to so and so's data.
OK, well, actually now I've messed that up a bit.
I've been thinking too much sun.
Let me off guys.
What I mean to say is there is a way in Firebase or for you in Firebase Database to add the user I.D.
that created the data to go and look at the documentation.
And I want you to try and add the user ID to it.
And then within the application itself, I want you to limit the messages a user can access to those
with his own ID, i.e. the ones that he wrote.
Now, this is a very, very difficult task if you are a new programmer, very, very difficult.
But your starting point is the firebase documentation and looking around inserting or accessing data
via user ID, that will give you a lot of the answers that you're looking for.
And once you've got those answers, you will then need to modify this very slightly, probably very
slightly, to include the current user ID and return that user IDS data.
OK, so that's the very difficult task.
I'm not going to give you solutions to either of these tasks because I think that good developers are
born from create from solving hard tasks that you don't have the solutions for.
That is basically what we have to do every single day.
So you might as well get started now.