Our author reducer is all set up.
Now we need to think about the different state properties that this thing is going to manage and how
we might want to change them.
So the best way to do this is to go back over to our diagram over here and really think about the different
ways that we would want to manage or change the state inside of our auth provider.
So I think that there are probably three very obvious locations where we probably want to change some
information related to our users authentication status.
The first one is probably art sign up screen.
So I think that our sign up screen needs to have some way to change our authentication state or kind
of initiate a change.
In other words whenever a user enters email and password and hits that sign up button we probably want
to send some signal over to our auth provider until it.
Hey you need to go and try to sign up with the API or something like that.
So I'm going to draw in that line right there and I'll put in a little red box just indicate the information
that we really want to share.
So I think that we want to say something like from the sign up screen over to our provider tried to
sign up and maybe we should also pass along the email and the password that the user entered into that
form as well.
It's that some signal that we want to send from the sign up screen over to our auth provider.
The second location where we probably want to do something like this is our sign and screen.
So whenever a user enters a email and password there as well we probably want to send a signal from
the sign and screen over to the author provider and say something like hey please tried to sign in.
And once again in this case we play I want to send along an email and a password as well.
Now the final location.
Remember I said there's gonna be three three places where we want to change some information stored
inside of our off provider is going to be our account screen.
Remember that account screen is going to have a single button on it over here that says sign out.
So whenever user taps that button we probably want to once again change our authentication state.
So whenever user taps that button we will probably want to share some information or send it in little
notification of sorts from the account screen back to our auth provider and say tried to sign out so
in all three cases we want to essentially change our state in these two over here we're gonna provide
some data along with that request to change our state but in account screen there's really no data to
send along we're really just kind of sending a notification that says hey please try to sign us out
of the application so it's going to be up to the auth provider to implement some different action functions
that are going to teach take each of these different signals and then somehow update the state stored
inside the provider and say OK we're either now signed in or not signed in or whatever else now that
we've got a reasonable idea of the different ways we need to change our states and where we are changing
it from let's try to create some different action functions inside of our off context file and just
kind of get a good idea of what we're going to try to do inside of each of those so back inside my off
context right underneath my auth reducer I'm going to write out the scaffolding for three different
action functions three different ways that I want to change my state.
So my first function I'm going to call sign in.
Actually let's go in order here we'll call it sign up.
Remember whenever we create an action function it's going to be a function called with dispatch that's
going to return a function and the inter function right here.
That's what actually gets called inside of our component.
The only reason we've got this setup right here is that remember inside of our create data context we
need to get access to the dispatch that is only given to us right here.
So the only way that we can really get that variable available inside of our actions is to go through
this entire bound actions process call each one of those different action functions with dispatch and
that will give this inner function right here access to the dispatch function that we really care about.
So then inside of sign up remember this function right here is going to be what is called from our component.
It's like we just said we probably want to make sure that whenever we try to sign up we pass along the
email and password that the user is trying to sign up with.
So I'm going to imagine that this function right here that's going to eventually be called my component
is going to receive an object that's going to have the email and password that the user is trying to
sign up with so then inside of here we can start to think about the different steps that we probably
want to go through inside of your well chances are I think that we need to probably make a make API
request to sign up with that email and password.
So in other words make a request off to that express API that we just built and setup and try to sign
up with that email and password and then after that if we sign up then we probably want to somehow modify
our state and say that we are signed or let's just say authenticated.
So if we sign up remember we then get back at Jason web token.
So we probably want to say OK well we are now signed up we're signed in we're authenticated.
So you want to modify our state managed by our author reduce the right here to reflect the fact that
we are now authenticated.
We also need to consider the case in which making this API request would fail.
So if signing up fails we probably need to reflect an error message somewhere or something like that.
So in total I think that's what we need to do inside of our sign up action function we need to make
our API request if it goes through we need to modify our state say that we're now authenticated.
Otherwise if that process fails we need to somehow show an error message to the user in some way to
let our user know hey sorry but like that's about email password maybe the emails already in use made
that request failed.
Whatever else.
That's a good kind of first stab at sign up let's not do the same thing for.
Sign in and sign out as well will you sign in so we're gonna get our dispatch.
We're going to return once again.
I think that we're going to call that thing with a email and password inside of an object so I can receive
those arguments right here.
And we're going to once again go through the same steps I'm gonna put some comments inside of here by
going to abbreviate them significantly.
So I'll say tried to sign in handle success by updating state handle failure by showing error message
somehow and we don't really know necessarily how to best show an error message to the user but we'll
figure that out and just a little bit.
And then finally we can stub out our sign out as well.
So whenever we try to sign our user out well there's really no information we're taking along no parameters
no arguments or anything like that.
So all we really have to do here is somehow sign out OK.
So those are three different action functions.
So let's now wire those up down here to our create data context just to make them available to all of
our different screens.
So inside of here I'll put sign in sign out and sign up
okay.
That's a good place to get started.
We at least have a idea of the different things we're going to do inside of this context object.
So now that we've got this stuff put together another quick pause and we come back in the next video
we're gonna start to wire up Acciona inside of our project and just make sure that we can actually access
our API because it definitely seems like the next step here is to make sure that we can make an API
request to that express API we've put together so quick pause and some setup in the next video.