Learn JWT in 10 Minutes with Express, Node, and Cookie Parser

  Рет қаралды 111,151

Web Dev Cody

Web Dev Cody

Күн бұрын

Пікірлер: 162
@WebDevCody
@WebDevCody 3 жыл бұрын
If there is anything you were disappointed I didn’t talk about in this video, let me know and I’ll make another video to cover it. Maybe refresh tokens is something I could have covered.
@Dylan-yc9qs
@Dylan-yc9qs 3 жыл бұрын
Great video man this helped me a lot. Can I just make one tiny suggestion for future videos? So ive used JWT without cookie parser so im familiar with how JWT works. I think it would be more helpful to a wider audience of people if you coded some of the stuff in the video. Just a tiny suggestion because I believe you are really good at explaining these things. Anyways thank you for the video!
@velara314
@velara314 Жыл бұрын
If the user interacts with the site then the timeout resets correct? Is JWT a library on npm or an approach for authentication? Have you thought about creating a basic register/ login site?
@wiktorwachowski6291
@wiktorwachowski6291 Жыл бұрын
Yes, exactly that's what I thought. You should have at least mentioned them even if you didn't plan to go deeper so others could get to know that this thing exists
@James-g9n5e
@James-g9n5e 2 ай бұрын
awesome dude....in 10 minutes you covered something that troubled me for hours...thank you.
@MMH94MMH
@MMH94MMH Жыл бұрын
I'm a PHP developer and this topic was one of the most confusing parts for me and I was looking for a simple explanation to understand this concept and you did very well, thank you very much.
@gavinv.4872
@gavinv.4872 2 жыл бұрын
You are a legend! After combing through videos with people never quite explaining how to generate/store JWT tokens (securely), this was the video that put it all together. Thanks! My login portal will be built in your honor😆
@duygukocar7623
@duygukocar7623 2 жыл бұрын
Amazing! I spent 2 hours trying to understand this simple thing from other videos. Thank you !
@knightOfGamingGames
@knightOfGamingGames Жыл бұрын
You saved my brain from burning out! Thank you for explaining what JWT does!
@SlainR2
@SlainR2 3 жыл бұрын
I really like your videos, the manner you present the content always catchs my attention. Great work! Could you do a full youtubes series about Authentication/Authorization?
@WebDevCody
@WebDevCody 3 жыл бұрын
Yeah that’s probably a good idea. A lot of people seem confused about auth / authorization / jwt in general
@WewCode
@WewCode Жыл бұрын
hey man long term viewer here! i just wanna say even your old videos really help me out i was trying to get my jwt to work for the last 3 days and i finally got it thanks to you and another youtube ben awad! just wanted to say thank you!
@WebDevCody
@WebDevCody Жыл бұрын
Glad to hear it! I sometimes think those old videos become useless after some time.
@fullstackmarketing247
@fullstackmarketing247 4 ай бұрын
Lol I was literally 30 seconds and I had to stop and subscribe to this guy. I already know he's going to be excellent at explaining
@Kyle-wc6so
@Kyle-wc6so Ай бұрын
I like the way you explain this. thorough and effective. thank you
@meghanathshetty1797
@meghanathshetty1797 6 ай бұрын
simple explanation for such an confusing topic, Thank you
@slimyelow
@slimyelow Жыл бұрын
Chome will not set the cookie. It is received in 'Network' but in the 'Application' Tab it does not.
@deepanshukant392
@deepanshukant392 Жыл бұрын
You found any fix to it?
@newtonw.1937
@newtonw.1937 Жыл бұрын
I have the same problem....did you find a fix??
@krishnakanthati8510
@krishnakanthati8510 Жыл бұрын
Did you find anything?
@Howtoclaim101
@Howtoclaim101 7 ай бұрын
Did you find anything?
@liveupdate6467
@liveupdate6467 4 ай бұрын
You have to set the 'Access-Control-Allow-Credentials' header by the server and if you are using axios or fetch, the add a 'withCredentials' option and set it to true
@mohitpal1505
@mohitpal1505 2 ай бұрын
cookieParser is not for putting jwt in the users' cookie, but instead to read the cookie from incoming users requests for authorizing. When it comes to setting up the cookie initially by the server, that can be done without the cookieParser too
@ares5751
@ares5751 7 күн бұрын
im a student and i am only developing on localhost at the moment. could you please explain if this requires an actual extablished connection (which i dont know how to yet) or if i can slap this on my project and will work on localhost without issues? i saw you have declared a variable for a port, but thats where my knowledge about connections ends
@hoanglongluong4355
@hoanglongluong4355 3 ай бұрын
With your doing, I wonder if two different account logins are on the same device. How did the server return and manage their cookie & token? Can you explain this situation, many thanks
@pedromora3520
@pedromora3520 2 ай бұрын
Wondeful! The content was clear and very informative. It helped me figure things out. Thank you a lot!
@rotivanov
@rotivanov Жыл бұрын
Dude you are AWESOME! You are helping me to achieve so much! I love your work mate!
@githmin
@githmin Жыл бұрын
Best explanation on JWT. TYSM!
@KashanPardesi
@KashanPardesi 11 ай бұрын
That was awesome, quick and to the point! Thanks!
@RaviKumar-wx1yt
@RaviKumar-wx1yt 7 ай бұрын
Do we need to do anything on UI for setting up the cookie? I am receiving the Set-Cookie header but not seeing in the browser
@whiteknife5993
@whiteknife5993 5 ай бұрын
same problem. Did you solve it?
@leonardoveque7157
@leonardoveque7157 10 ай бұрын
I wont watch your video because in the title has 10 minutes but actually have 10 minutes and 19 seconds. Great video my friend, merry christmas
@WebDevCody
@WebDevCody 10 ай бұрын
😂
@israelruas948
@israelruas948 7 ай бұрын
Thank you so much. Your video saved my application
@fluttterdev1k
@fluttterdev1k 3 ай бұрын
In my code, I store the refresh token inside an HttpOnly cookie. Every time a user wants to open the website, it checks if the refresh token cookie is expired. If it is expired, the user is logged out and asked to log in again. If it is not expired, a new access token is created and the user is taken to the homepage without being asked to log in. The access token expires after 15 minutes, and at that point, the refresh token inside the cookie is checked again. If the refresh token is still valid, a new access token is created automatically, and the API request is made. Is there a problem with this approach?
@planetmall2
@planetmall2 2 жыл бұрын
This is an amazing example and explanation. Thank you.
@DalisYn
@DalisYn Жыл бұрын
this was such a clear explanation
@soduno596
@soduno596 4 сағат бұрын
What is going through my head is if the user guess the secret thats on the server, then they can easilly manipulate the JWT? Would it be valid to use secrets rotation for this purpose?
@WebDevCody
@WebDevCody 3 сағат бұрын
Yes but how would a user guess the secret? If it’s 32 characters long it would take way over a trillion years to brute force. But yes you should rotate secrets every so often in case you leak one
@gonzalorobledo9947
@gonzalorobledo9947 6 ай бұрын
Excellent explanation, one question, in localhost everything works fine when connecting frontend with backend, but in production (backend in railway and frontend in vercel) the cookies never arrive to the front and therefore does not start the session, what can I do?
@WebDevCody
@WebDevCody 6 ай бұрын
I’d probably get your api hosted as a sub domain and setup the policy to allow wildcard certs so the same cookie will be forwarded on both the ui and api requests. If you put something in front such as cloudflare, it’s possible to make rewrite rules do your api can be accessed with a /api subdomain path I think
@gonzalorobledo9947
@gonzalorobledo9947 6 ай бұрын
Ok, thanks!
@AliAliOxenFree
@AliAliOxenFree Жыл бұрын
Nice explanation! Earned yourself a sub with this banger
@VayunEkbote
@VayunEkbote Жыл бұрын
I can see the set-cookie in the response headers but cannot see the cookie in the application tab. Why is it so?
@newcode7847
@newcode7847 Жыл бұрын
Hi, did you find any solution ?
@VayunEkbote
@VayunEkbote Жыл бұрын
@@newcode7847 you need to set the secure to true
@TyquanWorldNN
@TyquanWorldNN Жыл бұрын
@@newcode7847 You have to set the domain value to "localhost" when your making a res.cookie([nameofcookie], [value], {domain: "localhost", path:"/"})
@bamideleprecious3481
@bamideleprecious3481 Жыл бұрын
​@@VayunEkbotestill not working
@haritpatel5001
@haritpatel5001 8 ай бұрын
we gotta send the withCredentials: true, in axios while making a request, it should resolve your problem.
@rodrigocasarinperea4422
@rodrigocasarinperea4422 Жыл бұрын
Thanks broo! This is exactly what I was looking for
@piegpa
@piegpa 3 жыл бұрын
Nice one, good overview, thanks!
@WebDevCody
@WebDevCody 3 жыл бұрын
Glad you liked it!
@GarmrZero13
@GarmrZero13 3 жыл бұрын
I think refresh tokens would be cool to go over. Ive been fiddling with them but have not yet figured a 'good' way to refresh a jwt with react
@WebDevCody
@WebDevCody 3 жыл бұрын
I could do that next probably. Idk if I’ll do it in react since the concepts I cover apply to all frameworks basically
@myke6972
@myke6972 4 ай бұрын
Hello, Im having an issue where there''s a response header for set-cookies, but no cookies ion the application storage, why is that?
@myke6972
@myke6972 4 ай бұрын
please answer D: i literally keep searching for 5hours now, ofcourse i have breaks but its been 5hours, and im just a abeginner
@aniketbhalla1521
@aniketbhalla1521 Жыл бұрын
Please do the same video video by setting the http only cookie at the frontend in a react app, making the SPA app's routes protected with each request. And also with sameSite set to strict. I'll be thankful.
@emiremark2889
@emiremark2889 6 ай бұрын
fantastic explanation
@unitybr3222
@unitybr3222 2 жыл бұрын
Thanks, you saved my world!
@mgnfy-view
@mgnfy-view 7 ай бұрын
Well made video. Got it down instantly!
@asfandiyar5829
@asfandiyar5829 Жыл бұрын
Exactly what I wanted. Thanks
@shahidabbas2932
@shahidabbas2932 2 жыл бұрын
Sir setting req.user = user not working in typescript ? const user = jwt.verify........... how it extract user from jwt automatically?
@brunonery8098
@brunonery8098 3 ай бұрын
Thk bro! Thats a great video!
@darkfoxwillie
@darkfoxwillie 3 жыл бұрын
Hello bro! Good video in fact it was for a video of tokens that a subscribed to your channel jeje. A question my bro, how should I store the token? Also why and how I need to use refresh tokens. Thank you very much for your videos they are really useful :)
@WebDevCody
@WebDevCody 3 жыл бұрын
People say to store the token in a cookie similar to how I did in this video. I personally think you can store it in local storage just fine if needed
@7906jun
@7906jun 3 жыл бұрын
FIrstly, thank you so much for this video. It helped me so much. I hope you reach your subscribers goal. But I have one question. So, I noticed that you did "req.user". The user contains id, iat, and exp. But you never used this "user" you sent to the request object. So my question is, how and when would you need to use this "user" ? Thank you for your time.
@WebDevCody
@WebDevCody 3 жыл бұрын
You would use the req.user.id to fetch data from the database that belongs to that id.
@DaviMartins99
@DaviMartins99 Жыл бұрын
Such a great lesson!
@naufalnasrullah6965
@naufalnasrullah6965 2 ай бұрын
3:53 Is it the backend, not the frontend, that set cookies on the user's browser? pls answer me :(
@WebDevCody
@WebDevCody 2 ай бұрын
The backend sets a response header which tells a browser to store a cookie
@naufalnasrullah6965
@naufalnasrullah6965 2 ай бұрын
@@WebDevCody in other word, frontend don't need to set the cookie again right?
@WebDevCody
@WebDevCody 2 ай бұрын
@@naufalnasrullah6965 correct
@naufalnasrullah6965
@naufalnasrullah6965 2 ай бұрын
@@WebDevCody is it best practices that used by industries/developer? I'm still student so i confused..
@blazi_0
@blazi_0 Ай бұрын
​@@naufalnasrullah6965 yeah bro absolutely, also you need a route to refreshing tokens so when token expires on front end you his this route to get and set new token in the cookies
@rjwhite4424
@rjwhite4424 7 ай бұрын
so every 15 minutes I have to log back in?
@sede189
@sede189 2 жыл бұрын
Nice job. May be you can add another section to use an actual oauth issuer like okta
@newtonw.1937
@newtonw.1937 Жыл бұрын
The set cookie is received in 'Network-(response header )' but in the 'Application-(cookie storage)' the cookie is not saved by the browser😔😔 ----help?? anyone??
@darshanprajapati9601
@darshanprajapati9601 18 күн бұрын
cookie-parser is not working on production this is working only in local
@piotrjasiulewicz408
@piotrjasiulewicz408 6 ай бұрын
god tier tutorial
@manzelo9855
@manzelo9855 Жыл бұрын
Really good work man :D
@daredevil5186
@daredevil5186 9 ай бұрын
Amazing video man!
@seanfrancisco76
@seanfrancisco76 2 жыл бұрын
Do you have a file that works for aptopayments specifically? thanks!
@neoTriny
@neoTriny 7 ай бұрын
Thank you sir, its awesome 🤝
@CansinLale
@CansinLale 4 ай бұрын
Cookies header is full but cookie is not stored
@andylib
@andylib 2 жыл бұрын
This was great, thank you!
@hemersonallan
@hemersonallan 2 жыл бұрын
1 million likes !!!! tnx
@smitagravat1063
@smitagravat1063 2 жыл бұрын
I am getting token in postmen but it is not being saved in cookies in chrome
@deepanshukant392
@deepanshukant392 Жыл бұрын
You found any fix to it?
@tfandrad3
@tfandrad3 Жыл бұрын
Me too, anyone fix this?
@whiteknife5993
@whiteknife5993 5 ай бұрын
Did you fix it?????????????😭😭😭😭😭😭😭😭
@smitagravat1063
@smitagravat1063 5 ай бұрын
I fixed it like a year ago and now forget what was the problem
@awaraamin6850
@awaraamin6850 Жыл бұрын
Great input, thank you
@egeozel80
@egeozel80 9 ай бұрын
Very nice, thanks and good job.
@AhmedHuzain
@AhmedHuzain Жыл бұрын
Very useful. Thanks!
@tunaalkan5407
@tunaalkan5407 8 ай бұрын
Thank you do you have the full tutorial?
@SeibertSwirl
@SeibertSwirl 3 жыл бұрын
Good job babe!
@mrlectus
@mrlectus Жыл бұрын
does this also keep the user logged in?
@satorugojo7140
@satorugojo7140 Жыл бұрын
can you help me with authorisation through headers
@RatherBeCancelledThanHandled
@RatherBeCancelledThanHandled 8 ай бұрын
Well explained :)
@ramiworkstation
@ramiworkstation 2 ай бұрын
Thank you 💌
@tibz9257
@tibz9257 2 жыл бұрын
Thanks for this tutorial! Was really helpful but I can't get the "Token" Cookie in the "Application" tab even if I have the "Set-Cookie" in the Network response Headers... I'm looking at some forums but it looks like Chrome don't want to set cookies on URL with port since a few version.. Any idea?
@WebDevCody
@WebDevCody 2 жыл бұрын
Double check secure is not set, and you have an expires value set? You also might need to set withCredentials: true if you’re using axios
@eyaouni-vg4ji
@eyaouni-vg4ji Жыл бұрын
@@WebDevCody thank you very muck i was searching for solving this problem for 7 days and u have help me i'm so thankfull for u ..Big respect
@tfandrad3
@tfandrad3 Жыл бұрын
​@@eyaouni-vg4ji help me bro
@henriqueb5637
@henriqueb5637 Жыл бұрын
@@eyaouni-vg4ji Could you please share how you managed to solve this problem?
@henriqueb5637
@henriqueb5637 Жыл бұрын
@@tfandrad3 I have the same issue. Did you find the cause? Please share it
@MrMome1612
@MrMome1612 2 жыл бұрын
Your hand is freakishly huge😱
@Yusuf-ok5rk
@Yusuf-ok5rk Жыл бұрын
best comment ever
@germanoller4418
@germanoller4418 10 ай бұрын
thanks mate, raelly helpful
@sekarana9865
@sekarana9865 3 жыл бұрын
Hi could you please clarify my doubt if some one steal a valid JWT token and send behalf of us , how it should be validated in this case..
@WebDevCody
@WebDevCody 3 жыл бұрын
if someone steals your token there isn't much you can do, and it would probably be hard to know if your token was stolen in the first place. You could try implementing some type of blacklist to check if the token should be considered "invalid", but at that point, you are defeating the purpose of using JWT for stateless requests.
@sekarana9865
@sekarana9865 3 жыл бұрын
@@WebDevCody Thanks for prompt update..keep up the good work..
@peytoncastillo4508
@peytoncastillo4508 Жыл бұрын
Great video!
@r0bits593
@r0bits593 Жыл бұрын
I dont understand how does your browser know on how to save the received cookie in the Application -> Cookies tab
@WebDevCody
@WebDevCody Жыл бұрын
the browser inspects your headers for the Set-Cookie response header, and if it sees it, it'll store the cookie in the browser's cookie storage
@r0bits593
@r0bits593 Жыл бұрын
@@WebDevCody Done! Thanks, its working now
@vladislavivanov1546
@vladislavivanov1546 3 жыл бұрын
Hey man, what's the name of the theme you are using? It looks smooth
@WebDevCody
@WebDevCody 3 жыл бұрын
shades of purple
@vaisakhgopinath3346
@vaisakhgopinath3346 3 жыл бұрын
Nice explanation
@WebDevCody
@WebDevCody 2 жыл бұрын
Thanks for liking
@Robin-os1os
@Robin-os1os 11 ай бұрын
Thanks cookie parser !
@sharathkk1807
@sharathkk1807 8 ай бұрын
very useful tnq
@nqssss
@nqssss Жыл бұрын
THANK YOU SO MUCH
@ruhitbaidya9910
@ruhitbaidya9910 Жыл бұрын
Pretty explain ❤️❤️❤️
@dorianmayamba6177
@dorianmayamba6177 Жыл бұрын
Question why can we still access it in the browser if it’s in http only?
@WebDevCody
@WebDevCody Жыл бұрын
Like access it in dev tools? Http only just means you can’t access it from javascript, this prevents any malicious script from reading your cooking and then forwarding them to the hacker. I think they keep all cookies visible in the browser so that users can see and delete cookies; you wouldn’t want a browser storing tons of cookies users don’t even know about
@dorianmayamba6177
@dorianmayamba6177 Жыл бұрын
Alright so Chatgpt could be wrong 😂😂 I mean it makes sense because I saw that when the user tries to access it by the key it returns an empty string
@ammarys9980
@ammarys9980 8 ай бұрын
quick note, YOU DON"T NEED cookie-pareser anymore.
@sabuein
@sabuein Жыл бұрын
Thank you.
@mjylove2
@mjylove2 Ай бұрын
awesome
@justine_chang39
@justine_chang39 Жыл бұрын
awesome video
@FirstLast-rp7jq
@FirstLast-rp7jq Жыл бұрын
can you make a tutorial with refresh token?
@learncomputer8526
@learncomputer8526 Жыл бұрын
My jwt token not store in cookie
@learncomputer8526
@learncomputer8526 Жыл бұрын
Solution kha ha
@iiinicky6224
@iiinicky6224 Жыл бұрын
Thanks!
@velara314
@velara314 Жыл бұрын
Just started this video and at 1:28 you have at line 8 you are destructuring the request body into an object. but what is the variable name!?!? …nevermind. i see. it’s not destructuring into an object but two variables. 🙄
@georgeomara
@georgeomara 6 ай бұрын
💯
@rajendraraj8810
@rajendraraj8810 3 жыл бұрын
Subscribed!..
@notfadeaway6617
@notfadeaway6617 Жыл бұрын
nice video.
@Robert-3691
@Robert-3691 7 ай бұрын
I'm in love with this content. I recently read a similar book, and I was completely in love with it. "Mastering AWS: A Software Engineers Guide" by Nathan Vale
@armankazi1799
@armankazi1799 2 жыл бұрын
Vs code theme name?
@DollyCleveland-l1f
@DollyCleveland-l1f 19 күн бұрын
Jones Nancy Lee Kenneth Garcia Cynthia
@LanBothan
@LanBothan 6 күн бұрын
Lopez Frank Smith Kenneth Harris Eric
@WalterWilliamse-i3s
@WalterWilliamse-i3s 28 күн бұрын
Davis Matthew Harris Steven Brown Angela
@graphiclife5416
@graphiclife5416 12 күн бұрын
expiration 1 hour, that is so unrealistic. So person needs to login every hour. Come on don't just copy paste tutorials from other people.
@WebDevCody
@WebDevCody 12 күн бұрын
It’s calling teaching. If you want production quality get a job
@abulsyed4851
@abulsyed4851 Жыл бұрын
Hi when I use local storage to save my jwt, I can easily check if the jwt exists in local storage and protect my SPA pages - if the jwt is in local storage. But when I try check if the httpOnly cookie exists using Cookies.get('myCookie'); I get undefined. But I can see the cookie in the chrome dev tools. I noticed the only work around was to set the httpOnly to false and then I could see my cookie. So yeah my question is if I wanna store as httpOnly: true. How can I access the cookie so I can protect my SPA pages.
@WebDevCody
@WebDevCody Жыл бұрын
The cookie will be sent on your http requests automatically. Usually you add withCredentials: true for axios and credentials: “include” for fetch and it’ll attach the cookie on the request.
@abulsyed4851
@abulsyed4851 Жыл бұрын
@@WebDevCody no I mean how can I protect my react pages? Usually I would check if a jwt is stored in local storage and if it is, I will allow users to access the authenticated pages and vice verse if the the jwt doesn't exist in local storage. But with httpOnly cookie I'm unable to check in my react app if the cookie exists. I've tried for example but this only works when the cookie httpOnly is set to false. Can't I see if the httpOnly cookie exists from my react app? Since I want to check if it does - so then I can protect my pages.
@WebDevCody
@WebDevCody Жыл бұрын
@@abulsyed4851 oh you’d need to hit an endpoint on the backend such as /api/me to see if you’re authenticated or not. If it returns 200 status, keep a Boolean like isAuthenticated true stored in global state somewhere. When a route load, check for that Boolean and redirect if it is false
@jotaroisdarius1918
@jotaroisdarius1918 Жыл бұрын
@@abulsyed4851 your react app can't check it but your server can since it's httpOnly, so you'd have to create an endpoint to check if you have that cookie and then you'd handle things according to the response
@chel3391
@chel3391 2 жыл бұрын
Great job, thanks!
@roebienarnaiz
@roebienarnaiz 2 жыл бұрын
Great Video!
@AntonioHowland
@AntonioHowland 2 күн бұрын
Johnson Jessica Lee Susan Thomas Timothy
@LiamAlixsons-o1b
@LiamAlixsons-o1b 21 күн бұрын
Moore Sandra Perez Timothy White Donna
JWT Authentication Tutorial - Node.js
27:36
Web Dev Simplified
Рет қаралды 1 МЛН
Session Vs JWT: The Differences You May Not Know!
7:00
ByteByteGo
Рет қаралды 155 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17
Поветкин заставил себя уважать!
01:00
МИНУС БАЛЛ
Рет қаралды 6 МЛН
Ozoda - Lada (Official Music Video)
06:07
Ozoda
Рет қаралды 7 МЛН
How do server side authentication sessions work (express & cookies)
15:26
Cookies, Sessions, JSON Web Tokens (JWT) and More 🍪🔐
46:41
LearnWebCode
Рет қаралды 106 М.
Node Auth Tutorial (JWT) #1 - Intro & Setup
15:30
Net Ninja
Рет қаралды 268 М.
What Is JWT and Why Should You Use JWT
14:53
Web Dev Simplified
Рет қаралды 1,2 МЛН
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 632 М.
Node.js API Authentication With JWT
23:01
Traversy Media
Рет қаралды 556 М.
Why is JWT popular?
5:14
ByteByteGo
Рет қаралды 318 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17