In this video we're going to make one last change or author douceur.
At present this author reducer is always going to return an object that vaguely looks like this right
here.
So it will be an object with a single property of is signed in.
And that value will be equal to either no true or false.
So we're going to add in one additional property to this thing.
This other property is not going to make a lot of sense right now but it's going to make a lot of sense
later on as we continue developing this course member that the entire idea this application is that
we're going to eventually have an API server like this thing right here that's going to store a list
of all the streams that have been created by our users.
The other thing I want you to recall is that inside of our mockups we had said when we pull this markup
markups up right here.
So we had said that once a user is logged in a user should be able to delete or edit the streams that
they have created.
So at some point in time we need to make sure that each stream is somehow associated with the user who
created it.
So in order to do so we're going to essentially create each stream record inside that API server that
contains the ID of the user who created it.
Now at present we don't have any user ID or anything like that.
But it turns out that we do it through Google off.
Let me show you something really quickly.
I'm going to flip back over to my browser council at our application and I'm going to make sure that
I am signed in.
Make sure you are signed in as well.
If you want to write out this code to then inside my counsel I'm going to reference the off instance
with GA API.
Off to get off instance that current user so this current user right here is a reference to all the
information about the user who is currently signed in to our application inside of this current user
object.
Is the idea of the user who signed in now this idea is the Google ID for this user when this user created
their account through Google dot com like they went to Google dot com and sign up for new account Google
assigned them an ID automatically.
So inside of our application we're just going to reuse the Google ID for this user to record which user
created which Stream.
Now a lot of this stuff it's not going to seem super relevant right now but trust me as soon as we start
creating streams and trying to edit them this is going to make a lot more sense.
And figuring out how we make sure that a given user is only able to create and edit a stream that are
only able to edit and delete a stream that they have created.
So to actually get an idea out of this object right here we can reference current user get and then
call get Id like so and that right there is the ID of the user who has currently signed in to our application
if we sign out and then sign in as some other user like with some other gmail address or google address
the ID will be completely different.
So we want to essentially store this ID inside of our Auth. reducer or through our Auth. reducers.
So with that when we create streams at some point in the feature we can mark which user created the
stream very easily by using that ID.
All right.
So to do so we're going to first flip back over to our Google component and site if you're going to
go on down to on off change.
So when we call on sign in I don't want to just call sign in.
I went to call sign in and also in the idea the user who is currently signed in.
So I'm going to add as an argument to this action creator a call to our instance and we're going to
essentially write out the same code that you see right here to get the idea the currently signed in
user.
So right you're going to say this off dot current user don't get get ID.
Like so
now when we call this action creator we're going to also pass on the idea of the user who has signed
in.
So now we need to make sure that we open up our action creator as well received this ID as an argument
and pass it through to the reducer.
By assigning this ID to the action object as a payload property so inside of my actions index file I'm
going to find my sign in action creator is right here.
I'm going to receive that user ID as an argument and I'll add it to my action on the palette property.
Like so and so now finally and of her Auth. reducer This is the part that we worked up to Rubin to make
sure that when a user signs in right here we not only update the is signed in property we're going to
make sure that we also update the user id flag as well.
Now to really do this correctly I'm going to make sure that all my initial states I put on is the user
id and I'm going to initialize it to null with the value of nil.
That means that we don't currently have a user ID.
So then inside of this update right here for a case seinen I'm going to make sure that I update the
user id property and the new value for this property is going to come from action.
Payload.
Now when a user signs out we should probably also clear that property.
So when the user signs out we want to make sure that we don't accidently carry that user ID around because
when the user signs out that's pretty much it.
They do not want to be associated with our application any more.
So when a user signs out I'm going to update user id back to a value of NULL like so OK so that's pretty
much it.
Now let's do one more quick test over here.
We're not going to actually see any change to our application.
Nonetheless I just want to make sure that we can go through the entire authentication process without
seeing an error message.
So I will refresh the page then sign out and sign back in.
And it looks like I signed in successfully without any error message.
Perfect.
All right.
So that's pretty much it for authentication.
That's all we really had to do we put together the author douceur we put together the Google component
and these two very simple action creators.
So now let's take a pause right here.
When we come back the next section we're going to start move forward on our application and making sure
that a user can eventually create a stream and then eventually show a list of streams.
So quick pause and I'll see you in just a minute.