In the last section we got our sign up at least kind of doing something right.
You know we can send your message on here but if I enter an incorrect password I see authentication
failed pop up.
If I then replace it with the correct password I can attempt to sign it again but the message does not
go away.
So definitely we need to make sure that we clear out this error message.
Luckily it's really straightforward to do with redux.
Right here we've got a case in our inducer of log in user success.
So if a user just logged in.
Chances are there is no error message to show them right like we don't need to show an error message.
Surely they just logged in successfully so the authentication did not fail.
You don't tell me it failed when it clearly just succeeded.
So to get the message to go away we can just zero out the message like so.
So just an empty string on there and the error message should be should go away.
Is all refreshed now.
And also attempt to sign in.
You get the error message and I'll put in correct credentials and it goes away.
Fantastic just what we expected.
Now I want to show you something like real very small oddity.
OK and this is an oddity of firebase.
I'm just going to point out to you.
It is something that bit me just a little bit while developing this application.
I imagine some number of people out there are going to run into this and so I want to point this out.
Tell you what the behavior is right now so you can expect it while you're debugging your application.
I'm going to do a little interesting something here.
I want to put a new line about that logging user's success and I'm just going to say B C G.
What do you think is going to happen when our app runs this line of code right here.
Well we haven't declared a variable called ABC TFG.
Let's use something more reasonable like hello banana.
There you go.
So when this line of code is executed I'm going to expect an error message to occur.
Right.
I don't expect to see a big red error message on the screen in my simulator and say I have no idea what
variable you're talking about here.
OK that's what we expect that's what we want to have happen.
It's not going to refresh the simulator input.
Test test dot com.
I'm going to put it in my correct password.
So now I will expect this line of code to execute right here so I'm going to log in and I get.
Authentication failed.
How interesting right.
How interesting.
Surely this line of exit line of code is executed right like surely ASCII we just saw the error message
go away a second ago so I know it's hitting that line of code and I know I just put in the correct password.
But for some reason rather than throwing an error on this message right here I get authentication failed.
So this is again a little bit of an oddity of firebase something that can be a little bit frustrating
if you don't expect it so I'm going to tell you what it is right now.
You'll probably go like oh that's rule not helpful.
But you know hopefully they'll help you debug stuff in the future.
So I want you to remember that whenever we call or X whenever we press that loggin button right here
we are calling log in user right we call logging user.
We attempt to sign him with an email and password.
OK if we didn't not have that banana variable in there I would expect to hit Daut then call logging
user success.
We dispatch a log in the user success action and then it flows over.
So eventually we end up over here and the producer and I hit this line of code right here right.
That is my expected flow.
That is what I expect to have happen and I'm going to tell ya.
That is exactly what is happening.
We are hitting this line of code right here.
We are executing banana and an error is being thrown.
Here's the problem.
I want you to think for a second about our call stack right like the order in which we're calling all
these different functions.
So we hit sign in with email and password.
When that resolves we run this function right here.
So logging user success in dispatching that action.
We are still kind of like in the context of this it then.
Or like in the context of this promise.
So here's what's really going on behind the scenes logging user success runs.
We dispatched the action we hit that line of code and the reducer in areas thrown and firebase sees
the error in assumes that something went wrong with the request.
It assumes that the request failed catastrophically and so it goes over to this catch statement right
here and it executes the catch statement.
So that is what is really going on behind the scenes and I can prove it to you.
I'm going to put in here.
Err so I'm going to receive whatever argument this function is being called with and I'm going to count
the log.
Err like so.
All right so now I need to flip back over to the simulator.
I'm going to pull open my chrome Council.
Here it is.
And now I'm going to put in my correct credentials.
So I'm going to expect this to hit that banana line.
It's all logging now and boom I get authentication fails and at the con. I see banana is not defined.
Which is clearly not what I expect as not one and what I have happen.
But if you look at the call stack your you can see that yes we were inside of user log in success.
We attempt to dispatch an action and you know something else happening here basically we got hung up
back in the promise it hit the catch case because it assumes something went wrong with the request and
we ended up in the catch case.
Definitely not what we really expected as far as catching an air goes.
OK.
So again this is a real gotcha.
While using firebase not a great way to catch this one I'm going to recommend you do it for the rest
of the Course just keep this log in this log message right here.
And if you ever just ever so happen to make a mistake while using firebase especially as we're working
through its authentication stuff you will see the error message pop up on the screen along with that
like you know authentication failed message as well.
So a little bit of a gotcha.
This is a work around that we're going to use right now.
All right.
So we do have to fix up our douceur of course you know flip back over and remove that banana term.
And now I should be able to refresh get my error message
and then sign in successfully.
And see the error message go away.
Cool.
OK.
So looks good.
Let's take a quick break and then come back and finish up with all that.
You know making sure we show some spinners and all that coming good stuff.