Enter the URL of the YouTube video to download subtitles in many different formats and languages.
how's it going guys welcome back to the
next section of this series where we are
authentication system with account
password reset and awesome features like
right now i have my front end running i
and my database running of course so
make sure you are doing the same
right now um the app looks something
navbar with the words navbar and i guess
our home component is just displaying
the words home so of course we want to
so let's go ahead and do just that
all right so let's see first thing i
home component so into source containers
where's home there it is i want to just
i have bootstrap open here so just make
sure you just google bootstrap and then
navigate into the documentation here and
this one looks absolutely perfect so
i'm just gonna i'm gonna paste it in
actually what i'm gonna want to do is
so we're going to have class name here
of container and then it's complaining
because we have this horizontal rule
here which has to be a closing tag
so make sure you do that and then i'm
margin top here of five and i'm also
gonna make all these double quotes into
single quotes because i'm a little ocd
my single quotes so let's see what am i
beautiful let's delete this text here
this is an incredible authentication
yeah you can write whatever you want so
and this is going to be a login button
and this is going to be a link
so we have to bring that in so link
change this to a link this is going to
and the rest actually no this will be
and that should be good let's see how
and beautiful that looks lovely now
let's fix up this nav bar a little bit
there we go nav bar thank you let's find
like and that would be this one right
here so i'm just gonna go ahead and grab
beautiful let's go to components
nav bar and just paste all of this in
let's make the indenting look nice
there we go let's change all of these to
beautiful oh that looks a lot nicer
all right so this should be auth system
there you go this is going to be a link
and then i guess this button here let me
alright beautiful and then once again i
want all these double quotes to be
quotes of course you don't have to do
that but i am a little ocd and i like to
use single quotes so i'm just going to
let's see what else do i have to fix up
which is going to go to slash it's going
to say home and i can leave this to be
and then this stuff here is going to be
we're gonna have things like login
sign up and then we're also gonna have a
so let's just see i think i called it no
and i'm just gonna have it like this for
make this a link make this a link
okay that should be good so i can go to
sign up back to home beautiful okay
oh when i click this it isn't working
why is that that's because this has to
there we go now if i go to login i can
okay beautiful all right so we have that
working now let's go ahead and work on
our um action and reducers so what i
in this application is for whenever you
load the application it's going to check
whether the user is authenticated
and it's going to do that by checking
the local storage and seeing if there's
an access token in the local storage
okay so let's go ahead open up actions
auth and we're also going to need some
so let me just copy this down i'm going
authenticated success authenticated fail
and log out all right so here i'm going
this is gonna be an async dispatch
since we're gonna have asynchronous
and then also at the bottom here i'm
and then for this log out this one's
simple so i'm just doing it now
beautiful all right so here first thing
access i want to check if the access
and if it doesn't i'm just going to
otherwise we're going to go through this
authentication process here so
configurations so let me just grab
so config and i don't need to do this
or what am i doing so this will be token
and then gonna have a try catch
and of course if there is an error
then i'm going to do authenticated fail
and then right here i'm going to have to
and basically to demonstrate what i'm
verify token and i go ahead and send a
we see that we get this code with token
not valid so i'm actually going to use
so i'm going to copy this and i'm
that means we are successful basically
and then of course we have to actually
and let me just go ahead and grab this
i'm going to bring that right in here
and then this is gonna be slash
slash we're gonna bring in our body and
and then if in fact we do get this
response.data.code is equal to this
that means that there is an error so
an error here otherwise we got success
beautiful so that should be that for
now let's move on to the auth reducer
those things so authenticated success
authenticated fail and log out
so right at the top here i'm gonna make
a case for authenticated success
and then i'm going to do spread operator
with state and the thing i'm going to be
i'm going to go ahead copy this let's
and this one's going to be the fail case
have all the state the exact same and
it's going to change is authenticated to
false and then of course we're going to
have log out which is gonna be the exact
as login fail so we're just gonna remove
the access refresh token from the local
access refresh to null is authenticated
so there you go so that should all be
layouts and i'm going to need
i'm gonna need curly braces so let's
all right it's beautiful and then i'm
going to need the connect helper
this is from react redux and i'm also
i mean the one function i created which
the authenticated so i'm just gonna do
i'm going to do this first just so i can
and load user so i'm going to need these
let's wrap our layout with our connect
we don't have any map state to props so
this is just going to be null since we
authentication states in this layout we
and basically we want to run check
authenticated and we want to run
okay and then in this use effect
hook what i'm going to do is i'm going
run those two functions so props dot
authenticated and props dot load
and now one thing i can actually do is
login now and i can actually do this
part that we left out in the last
so let me go ahead uncomment this
is authenticated is going to be
map state to props so we're gonna bring
in and of course i have to bring this
here is authenticated and then i'm gonna
is authenticated if that is true
slash so redirecting them to the home
page if they are authenticated
okay beautiful let's see what we got to
um so i'm gonna actually build this real
and just kind of test things out
all right so now i'm gonna just remove
this build folder in the back end
go ahead delete that and bring in this
and then something that i could actually
do just to make this process a little
package.json we can adjust this build
so before we build what we can do is we
and then we can build and then we can
the build and put it into back end slash
let's go ahead and test this just to
so i removed it and there we go
so that worked it copied it into here so
that'll make it a lot easier now once we
we won't have to do the delete it here
copy it and put it into the back end
it'll just happen automatically okay so
let's check out our dispatch is that we
have here so authenticated fail user
loaded fail so perfect that's what we
would expect to see if we're not
actually authenticated and don't have
an access token in our local storage now
okay so perfect we're redirected to the
what's called the home page if i go to
login i literally can't because it's
okay so we have login success user
loaded success now let's go ahead and
and now let's see what happened
user loaded success so you see even if
we still remain authenticated so that's
and then of course i'm not doing
anything with this refresh token
i could include something with the
refresh token basically a purpose
for it could be let's say if you have
when you're logging in you could click
to remain authenticated and then
whenever you reload the app you can have
use this refresh token to get yourself a
and that way you keep remaining
authenticated i kind of left that out in
this series but i mean if people want to
i could always kind of add as another
okay so anyway last thing i want to kind
of do in this section before i wrap it
up is just have these links updating
and then i'm going to have curly braces
so wrap all this in curly braces
there we go now all of this is wrapped
so the guest links are basically going
the login and sign up and the auth links
is going to be when you're authenticated
log out button and then that's also
another thing we're gonna need
auth and then also gonna need
so let's go ahead and wrap this in the
this is going to be null for the map
state to props we're going to bring in
log out and we're also going to need to
and then actually we will have state
because i'm going to want to check
whether um is authenticated is
true and then that will determine what i
state dot auth dot is authenticated
there we go and then i'm going to want
is authenticated and then also gonna
want map state to props here instead of
null all right so let's get working on
links here and i'm also gonna need
and then this is going to run our logout
fragment since i'm gonna need that for
and then let me just grab these two cut
beautiful and then this one here
this is let's see i'm gonna also have
something similar just instead i'm gonna
with an href i'm just gonna have a
and actually i don't need this logout
handler i can just straight up do
out and then that should log us
have a condition here is authenticated
so if this is true what we're going to
is we are going to display our what is
so auth links otherwise we're gonna have
okay now let's go ahead and build this
okay so let's see what happened here
so navbar.js expected an assignment or
ah yes so i need to wrap these in round
round parentheses instead of the curly
my bad because we are returning jsx here
let's rebuild this all right now let's
test this out so let's refresh here
so if we go ahead and check what
happened we got authenticated fail and
our token probably expired so now we
in so let's go ahead and re-log in john
doe one two five seven nine one five
so let's log in we're redirected and
there we go it's updated to be
a log out button and if we go ahead and
we got login success user loaded success
let's take a look at our state we have
an access refresh token is authenticated
and we have our user and if we refresh
again we are still logged in if we click
out there we go the links are updated
let's check our dispatches here so we
so when we refresh we got authenticated
success user loaded success and then
log out and our access refresh is null
our users null is authenticated is false
beautiful and these links are updated so
so hope you enjoyed this section we
the navbar we made that homepage look
and then we also added the functionality
to check whether a user is authenticated
is refreshed so hope you enjoyed this
and i will see you in the next but
before that make sure you leave a like
if you enjoy the content on this channel
and if you are enjoying this series