UPDATE: at 55:20 the correct import syntax would be "import { jwtDecode } from "jwt-decode";". Then also update the initialization of the decodedToken later on by replacing "const decodedToken = jwt_decode(user.accessToken);" with "const decodedToken = jwtDecode(user.accessToken);"
@augustzilakovs3105 Жыл бұрын
After hours of googling and looking at other guides this is by far the best one. Straight to the point and covers exactly what you need to know about how to use JWT. Thank you.
@jeminaldennis3253 жыл бұрын
you're the MAN... long live Lama Dev
@javhaasuhochir81262 жыл бұрын
You are the best teacher I ever seen In my school and KZbin. So easy, so clear. This is the best tutorial I ever seen in my life. thanks my friend. You really saved my life from struggling with jwt for months. Really THank you man.
@Pareshbpatel Жыл бұрын
A very easy-to-follow tutorial on JWT Authentication in Node/React. Thank you, Lama Dev {2023-03-22}
@muhammadismail53423 жыл бұрын
Best channel on KZbin for MERN stack mastery.
@msunrl8577 Жыл бұрын
dude wtf, best tutorial of jwt, after checking like 10 Thanks!
@mdbillalyasir3 жыл бұрын
YOU TOOK MY REQUEST THANKS, DUDE! ALWAYS WILL GET SUPPORT.
@enriquealejand263 жыл бұрын
Thanks Man, I am from Venezuela, I don't understand much English, but I can tell you that your video is the best, coz there are not videos in Spanish that explained as I can refresh the access tokken.
@Jimmy-zt5io Жыл бұрын
yo tmb soy de Venezuela bro, lo malo aqui es que si uno refresca la pagina se se cierra la sesion del usuario
@wasteghost2 жыл бұрын
Really helpful tutorial, I couldn't find a good one for some time and yours is perfect!
@papesonko Жыл бұрын
Simple clear and concise, thank you very much lamadev !
@RianY2K3 жыл бұрын
thank you for tutorial, JWT is mandatory nowadays.
@shubhamdhumal6854 Жыл бұрын
best tutorial to learn understand and implement JWT. Great work!
@izureki2 жыл бұрын
The only insightful video on jwt, THANKS!
@haiphaminh14623 жыл бұрын
Thank you ! I was waiting for the full reactjs+nodejs make e-commerce website
@TomDoesTech3 жыл бұрын
Why is there a different endpoint to exchange the refresh token for a new access token? This seems like it would make building the UI very difficult as you need to try to hit the endpoint, see if the error is unauthorized, if it is, get a new access token and try again. I think this should be done automatically on every request. If the access token is expired, given them a new access token and continue processing the request.
@saravanan9253 жыл бұрын
thats what he did right?
@TomDoesTech3 жыл бұрын
@@saravanan925 He created an endpoint to exchange the refresh token for an access token. Is that what you're asking?
@marcusaureliusregulus28332 жыл бұрын
Did you watch till the end? There's a function on the frontend that automatically refreshes the access token if it is expired (No UI included)
@TomDoesTech2 жыл бұрын
@@marcusaureliusregulus2833 yeah, why? why not do that on the backend?
@marcusaureliusregulus28332 жыл бұрын
@@TomDoesTech I guess it could work either way.
@coder53363 жыл бұрын
I was waiting for the jwt tutorial. It's the best as always
@moshem49683 жыл бұрын
5 Minutes in I knew it's gonna be a great tutorial. Was right. Thank you!
@Matheus-lk9lh3 жыл бұрын
Your content is the best on internet, thank you very much
@bingsenlim31213 жыл бұрын
Hi I have a question. It seems like in this tutorial, you are always logged out after you refresh. In your React Social Media tutorial, you stored your user object in localStorage to let the user remain logged-in after page refresh. My question is, since you need accessToken to do stuff like delete posts etc, wouldn't you need to store accessToken in localStorage also? If you don't store accessToken in localStorage (only store in useState or useContext), after the user refresh the page he/she cannot delete post anymore since the accessToken state/context will be null. But if you store it in localStorage, doesn't this defeat the purpose of jwt, because hackers can see it from localStorage. So how do I use JWT, and at the same time, pass down this accessToken if my user refreshes the page?
@developerbox30793 жыл бұрын
same problem . did u solve it ?
@bingsenlim31213 жыл бұрын
@@developerbox3079 This is what I saw from someone's post from stack overflow: 1.When you do log in, api sends 2 tokens (Access token, Refresh token) in response to the client. 2.The access token will have less expiry time (may be 15min) and Refresh will have long expiry time (may be 7 or 60 days ) 3.The client (Front end) will store refresh token in his local storage and access token in cookies. 4.The client will use an access token for calling APIs. But when it expires, pick the refresh token from local storage and call auth server API to get the new token. 5.Your auth server will have an API exposed which will accept refresh token and checks for its validity and return a new access token. 6.Once the refresh token is expired, the User will be logged out.
@developerbox30793 жыл бұрын
@@bingsenlim3121 thank you! I will search more about it
@SF-qf4fu3 жыл бұрын
that's because he is giving the token a expiration of 5 sec, put 1d or in miliseconds 86400
@tusharverma22493 жыл бұрын
Please can you tell at which section of social media tutorial he save user in localStorage. I want to see but unable to find that part.
@SimpleCoding3 жыл бұрын
really awesome tutorial, love the way you explain things
@next_codes3 жыл бұрын
Hi Lama, Thanks for this great Tutorial, I want to specially request if you'd explain how to store the refreshToken in real Mongodb Database and not locally as an Array. I also would love to see what the refreshToken model looks like. would you create a separate schema for the refreshToken or just add it to the existing user model as type "Array" Please anyone can help me in this area, it's really challenging me.
@klhmia3 жыл бұрын
I think it's most secure to create the 'refreshToken' array as part of the User schema. This is what I've done. Then, instead of checking the local array as in this example, we would call an async method to find the user in our DB by Id (which we get after verifying token payload and returning the payload in the callback of 'jwt.verify()'), then check this User.refreshTokens array to see if it includes the refresh token and either add or remove depending on your action.
@jimenakatu11782 жыл бұрын
I would also like to see that and the other way that @Karsen LH said
@next_codes2 жыл бұрын
I have been able able to resolve the challenge. Thanks
@jimenakatu11782 жыл бұрын
@@next_codes You did it by yourself or with help of other tutorial?
@next_codes2 жыл бұрын
@@jimenakatu1178 I decided to try completing a full CRM /ERP project and along the Line I met more complex logics and situations. That exposed me to wider knowledge, turning back to check on this one, i found out it was just a walk over. I did it myself.
@vivekchaturvedi38972 жыл бұрын
i didn't understand "req.user = user", req.user stand for what? in 23:30
@yash_______1052 жыл бұрын
here we have assigned new property to req as like req have body , header now req also have user property. I hope u got it
@ryanpark35233 жыл бұрын
You are the best Lama~!! The content is so informative!! Thank you so much~!
@AdamElMou3 жыл бұрын
Thank you very much, I really love your videos, thank you for making us better everyday
@luckylovely77823 жыл бұрын
I love you so much. I want to support you but I lost my job for 4 months.
@jaggyjut3 жыл бұрын
when do we use JWT over something like Auth0 or Google Firebase Authentication?
@user-ul2mw6fu2e3 жыл бұрын
why you dont use refresh token in ecommerce project.I am little bit confuse with that
@ianfrye898811 ай бұрын
I love your videos. Thank you for this!!
@brianbg9413 жыл бұрын
I love your videos!. Thank you so much, greetings from Colombia
@praveen_javali3 жыл бұрын
very well explained !! thank you for JWT tutorial
@yasin_bhojani Жыл бұрын
Thanks very much, tutorial was very helpful.
@debajyotipila9823 жыл бұрын
It seemed really easy thanks for the tutorial.. Gonna revise again while making netflix clone (streaming platform) ☺️☺️
@yashmadaan80672 жыл бұрын
Thanks for your great tutorial
@mohitagrawal15553 жыл бұрын
i faced a problem in auth so i am writing this to help other : if your access token expire after some time then In axios Instance interceptor add "" config.headers["authorization"] = "Bearer " + accessToken; "" because after the token is refresh the axios instance headers will not update automatically . I Hope i was able to explain what i want to say.
@klim50263 жыл бұрын
Love your videos, thanks for the uploads
@souravsarker39133 жыл бұрын
Nice work. Just want to know why not making use of cookies ?
@otubusinademuyiwa3 жыл бұрын
You are doiing an amazing Job. Thanks
@amanagarwal80093 ай бұрын
i have a question. When i reload the page... it will ask for login credentials again and again.... How do i tackle that?
@ananthac64726 ай бұрын
why should we use the word Bearer before the token? , thanks :)
@okhunjongaybullaev25593 жыл бұрын
Helpful information, thanks
@shakthinaarayananr76392 жыл бұрын
Why you are using state variable to store the user Data ? Can we store it in cookies/local storage ?
@jellyfish1772 Жыл бұрын
Okay I have a question.anyone help ? When logging out why do I need to verify?I mean the goal is to delete the refresh token from the array.Its all about the refresh token! So why bother sending the access token as well?? We did not send the access token when refrshing,,because that was also about the refrsh token!
@saulehuu58673 жыл бұрын
Do you have a project to configure interceptors for the entire app?
@thomasc25323 жыл бұрын
How am I supposed to store the refresh token in my mongo database? should every user have their own refresh token so i call it like 'user.refreshToken' or should they be completely separate from users ?
@saravanana51252 жыл бұрын
You can add a new refresh token in users model.
@siamahnaf6760 Жыл бұрын
But, we miss logout from react. How can we stay logged in. Should I store refresh token in browser cookies or local storage
@javalover75703 жыл бұрын
Abi videoların baya güzel yeni fark ettim kanalı. :) Teşekkürler videolar için.
@birkbirk12042 ай бұрын
hocam selamlar, ben daha yeni başladım kodlamaya, videonuzu izledim teşekkür ederim sonra, uyguladım kendi uğraştığım bir siteye, access token ve refresh token elde ediyorum. refresh tokenları backende yönlendirdim orada tutuyorum. örneğin bir post atma işlemi yaparken kullanıcının access tokena erişimi olduğunu kontrol ediyor ekstra olarak, backende bakıp refresh tokenlede eşleşme şartı koydum. video başında dediğiniz gibi kullancı 2 nin sadece ismini bulup işlem yapamıyor. yeterli midir basit bir websitesi için
@chilly21713 жыл бұрын
Why did you have to put Bearer in the request header value? I don't understand. Why can't we just put the token there without the bearer.
@lakshaythegupta2 жыл бұрын
What do delete user means? If the user is deleted how were we getting the access token with new refresh token even after deleting when we refresh?
@islamicinterestofficial3 жыл бұрын
hi, I want that when a person reload page then it still logged in. How to implement this in jwt. I implemented in using local storage but its not good as discussed.
@Ahmadavocado2 жыл бұрын
have you figured it out?
@islamicinterestofficial2 жыл бұрын
@@Ahmadavocado yes. Just simply store the user id and jwt token in local storage. Then u are good to go
@Ahmadavocado2 жыл бұрын
@@islamicinterestofficial why not store it in cookuies and enable httponly? localstorage is not so safe
@islamicinterestofficial2 жыл бұрын
@@Ahmadavocado Its upto you. By the way cookies are also not safe. We're just storing which no one can understand because we only know the key not anybody
@komalsethi3295 Жыл бұрын
Very helpful content thanks👍
@marcusaureliusregulus28332 жыл бұрын
I have a confusion. While logging out since we are only removing the refreshToken and not the accessToken, wouldn't they be technically logged in for the duration of the access token?
@roshanparajuli Жыл бұрын
yes they would! Thats why you don't keep the duration of accessToken for more than 10-15 mins.
@muratkagan42603 жыл бұрын
Thanks for your great tutorial Şafak. Should we use NextJs framework for fullstack javascript applications? what do you suggest ?
@RiteshKumar-dx8wj5 ай бұрын
you were ahead of your time when you asked this question XD
@mauricenganga7202 жыл бұрын
Thank you Lama, you are the greatest
@arumugamp39293 жыл бұрын
Awesome explanation. Thanks.
@chilly21713 жыл бұрын
help, I'm doing this for my website but when user refreshes the page, the status is gone... wtf? Also, what's the point of a refresh token if you only bind it to a specific axios instance. So, if I go afk for 15 mins, I'll still get logged out, unless i delete a user.
@aimoneyminded3 жыл бұрын
Lama we can't add new lines in the blog description. Can you please see to it?
@sarwaranwar34852 жыл бұрын
lama please make video on otp and email verification. You have helped us alot thank you so much
@sede1892 жыл бұрын
super nicely done tutorial
@codersdance7 ай бұрын
So with refresh everything will be lost beacuse of the state?
@adarsh-chakraborty2 жыл бұрын
Should i save refreshTokens in my User model on mongodb?
@josealexisbetancurmira6058 Жыл бұрын
Thanks for this great Tutorial...
@KazHachiOreki Жыл бұрын
hey at 23:27 can you explain me what "req.user = user "doing ?
@umargulzar29822 жыл бұрын
Is it possible to store JWT token on Server side not on Client side Cookies???
@kevinmaina52503 жыл бұрын
Hi Lama, Thanks for the tutorial. I'm however stuck when logging out. I'm trying to log out by redirecting back to another page but it keeps failing. Kindly assist
@thatsmeee11110 ай бұрын
Who can tell me why we create a new instance axios please i can't understand that
@mandayli96412 жыл бұрын
so refresh token is only there for refreshing access tokens?
@youhaveto20233 жыл бұрын
Hi,i tried using it with the blog project i'm stuck. Could you do the jwt tutorial with the blog project please
@alivelidurali3 жыл бұрын
you are my best teacher.
@kemerios12 жыл бұрын
23:42 what does next() does?
@newtechnology59412 жыл бұрын
After function verify() is finished, next() came into the picture to move into the new function (in this example we move on to arrow function (req,res) )
@kemerios12 жыл бұрын
@@newtechnology5941 Understood, thank you.
@ahamek Жыл бұрын
what keyboard you are using?
@dijiflex3 жыл бұрын
Shouldn't the access tokens be stored in a HTTP only cookie?
@profitmasterynow3 жыл бұрын
Yes they should you should use jwt and cookie-parser with httpOnly and secure if you have HTTPS
@noyou1743 жыл бұрын
my brain explode XD ,ty for the great content
@henrymou81283 жыл бұрын
It would be wonderful if you could use this tutorial on blog project. I really confessed. I can do only Auth . But i can not implement on blog project.
@benbenpigpig3 жыл бұрын
This is a really straightforward tutorial. Thanks Lama. Is there a reason why we must include "Bearer" in the authorization string?
@oscargm19793 жыл бұрын
Is "Bearer "
@iamshivarth3 жыл бұрын
You can add anything before the access token but it should be separated by space. eg: BeN . The concept is to split the value of the key 'authorization' in 2 parts. So after splitting, 'BeN' & '' will come in an array. You have to take only the real token so that it can be verified with the generated one. That's why lama has used const token = authHeader.split(" ")[1] ;
@themalelibrary50722 жыл бұрын
could this also be implented into vue?
@rajnarayan95583 жыл бұрын
thank you sir i was wating for this
@Corntrop3 жыл бұрын
Awesome JWT tutorial
@didieroficialdev3 жыл бұрын
Perfect!!!!!! i will buy u a coofe! cheers from Perú btw you should make an example like Google auth i mean when you login from other country or device and google send you an alert if you are loggin from there... i hope you can understand thanks!
@agustinpolegre76672 жыл бұрын
the proxy doesn't work, any advice? :/
@ucthainguyen2892 жыл бұрын
Please can some one tell me how to link backend with React?I tried to login many times but nothing happened :(
@Harsh-eo7xo3 жыл бұрын
You are amazing. Love you.
@unfortunately8163 жыл бұрын
How can I make the client part tho..
@nuruhussen-wo9wg7 ай бұрын
best explanation
@shujathaliirfan26623 жыл бұрын
You are just fantastic
@GyaniTuber3 жыл бұрын
blog is responsive or not??
@abelmarkos57533 жыл бұрын
can you do some MERN Ecommerce tutorial with authenticatiom
@aniltheblogger3 жыл бұрын
Thanks for this tutorial
@ryansharpe9033 жыл бұрын
Really good tutorial although not all functions are then replicated on the front end, such as the Logout function. Is there a reason for this?
@chilly21713 жыл бұрын
It's quite a badly done tutorial. He even used refresh tokens wrongly, and login states are also saved wrongly. His methods won't work in practise, because if you refresh the page, you're logged out lol.
@gennbinaku76562 жыл бұрын
@@chilly2171 is there any tutorial how to stay logged in when you refresh the page using node js and express. 🙂
@raymondqiu8202 Жыл бұрын
@@gennbinaku7656 u probs have found out by now but i think u do it by saving the data to localstorage, that way it persists i think
@syed9846 Жыл бұрын
awesome tutorial
@modambheema46203 жыл бұрын
I'm beginner share command for creating api file ... Please
@saravananr72032 жыл бұрын
How to connect react js and node js?
@benarbiamohamedtaher5462 жыл бұрын
thank you ,great tutoriel
@jossesuryapinem42 Жыл бұрын
how about the logout ?
@fahimahmedsumon624 Жыл бұрын
thank you for this great tutorial ❤❤❤🫡🫡
@henrynguyen82823 жыл бұрын
Hi Lama, very appreciate for your tutor, If possible can you teach us how to pass axiosJWT in this video to contextAPI
@codelett21393 жыл бұрын
Are you from nepal coz you have name started with lama and here we have lamas and sherpas in himalaya😊
@mbmalek923 жыл бұрын
You are the great 👍👍 man
@saandial34123 жыл бұрын
Great tutorial thx! For registering, could you show how to implement admin approval needed before users can log in? This way only approved friends can create an account and sign in.
@klhmia3 жыл бұрын
Just create a separate database of 'temp' users to hold registered users waiting for approval. Allow admins to elevate those 'temp' users to 'active' users, moving them to the 'active' database which is the one you would used to sign users in.