So in the end here,
I wanna set a different server action depending on the mode.
And we can achieve this by going
to our auth actions file.
And there I'll add a new third Server action,
which I'll name auth.
And here I expect to get my mode
as a parameter followed by the previous state
and the form data.
And I then wanna check if the mode is equal to log in.
And if that's the case, I want to call that log in function,
that log in Server action and return that call
and pass that previous state and the form data to it.
Otherwise, I'll return the result of calling signup
and passing previous state and form data to it.
So that I use this as a helper Server action
to call the appropriate Server action depending on the mode.
Now, it's now that auth Server action that I want
to use in my auth form.
So here it's that auth Server action instead
of the signup Server action.
However, this auth Server action now needs to get
that mode information, and by default it wouldn't.
Now you can add extra data that will be added
to the Server action, though
by calling the bind method on this Server action function.
The bind method is a default method
that exists in JavaScript, which you can use
to preconfigure functions
so that when they will be executed,
they will be preconfigured in a certain way.
And you can, for example, preconfigure
what this keyword in that function will refer to.
And you do that with help
of the first argument you pass to bind.
But I don't care about that here, so I'll set this to null,
but any other extra argument you add thereafter
will actually be passed as a parameter
into this function when it's being called.
And that will be that mode then.
So that mode should be passed
as an extra argument into auth when it's being
called in the future.
And that's one way of making sure
that different Server Actions will be called
depending on the mode.
So if you save that and you reload
and you are in login mode,
and you try to log in with a nonexisting user,
which I here do, this is a user I have not created,
if I click login, I get this error.
If I on the other hand, use a valid email address
and a valid password, so the correct password for
that email address, I'm redirected to that training page
because now the user was logged in
and that off cookie was set.
And that's therefore, now of course,
another huge step forward
because this now is a working log in process.
Now as a last step, I actually also wanna make sure
that we have a header here at the top if the user
is logged in.
And that header should then contain a logout button,
which we can press to clear that cookie
and to, well, lock the user out.