JWT Authentication Tutorial - Node.js

JSON web tokens are one of the more popular ways to secure applications, especially in micro-services, but JWT is much more complex than a simple session based user authentication. In this video I will be breaking down exactly how to set up authentication with JWT and how to ensure the authentication is secure. I will also be showing how to setup refresh tokens with JWT so that your application is even more resilient and secure. Lastly, I will show how to invalidate refresh tokens which is the ultimate last step in securing an application.
📚 Materials/References:
User Authentication Video: • Build Node.js User Aut...
JWT Explained Video: • What Is JWT and Why Sh...
GitHub Code: github.com/WebDevSimplified/J...
🧠 Concepts Covered:
- Creating Node.js authentication middleware
- Using refresh tokens with JWT
- Authenticating users with JWT
- Invalidating refresh tokens to log users out
- How to use JWT securely
🌎 Find Me Here:
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#JWT #WDS #Authentication

Пікірлер: 862

  • @RasmusSchultz
    @RasmusSchultz Жыл бұрын

    If you're building your own authentication system, it's a really good idea to include a flag in your payloads, to indicate whether that token was generated by authenticating with user credentials, or by using a refresh token. You can use this flag to authorize sensitive operations, such as changing your password or making payments - so if the user didn't log in recently, you can prompt them to log in again for sensitive operations. I would say this is a must for most applications.

  • @abdulazeez.98

    @abdulazeez.98

    Жыл бұрын

    I’ve encountered this in some websites. Nice to know how it was implemented.

  • @duythinh252

    @duythinh252

    Жыл бұрын

    What a great information right there! Thank you for sharing. I immediately recognize the use of the flag in payload when I changing my facebook password for example, it requests me to re-enter my password again for authenticating with user credential

  • @aynuayex

    @aynuayex

    Жыл бұрын

    ya.we love to see how we can implement that.

  • @shahreazneeloy2119

    @shahreazneeloy2119

    Жыл бұрын

    You have a KZread channel. Please make a video on this topic

  • @mohammadalaaelghamry8010

    @mohammadalaaelghamry8010

    Жыл бұрын

    Thanks for the note. it helped me.

  • @aram5642
    @aram56423 жыл бұрын

    The single tutorial a dev should ever watch to get their heads wrapped around auth. Great pace and flow, pure English, pleasure to watch and listen to!

  • @ROCKEFELLAPRODUCTIONS
    @ROCKEFELLAPRODUCTIONS4 жыл бұрын

    You nailed these tutorials! I actually understand what you are explaining. You don't dilute it with unnecessary lingo in an attempt to sound smart. Thank you!

  • @SuperRockthing
    @SuperRockthing4 жыл бұрын

    I discovered your channel 30 minutes ago and I have already subscribed. Your way of explaining things with minimum jargon and straight forward approach is so refreshing.Keep up the good work!

  • @WebDevSimplified

    @WebDevSimplified

    4 жыл бұрын

    Thank you so much! My goal with the channel is to teach the most amount of content in the least amount of time, since time is the most valuable resource we have.

  • @serkanakman9945

    @serkanakman9945

    4 жыл бұрын

    @@WebDevSimplified that is what makes you and your channel great!

  • @phani123d

    @phani123d

    3 жыл бұрын

    @@WebDevSimplified great

  • @raymondyoo5461

    @raymondyoo5461

    2 жыл бұрын

    totally agree :)

  • @mosesegboh

    @mosesegboh

    Жыл бұрын

    True. He is one of the best ones.

  • @CodeDreamer68
    @CodeDreamer682 жыл бұрын

    Thanks for keeping it simple! You are living up to your name. I watched 5 other jwt videos from well-known vloggers, and was still left confused. This one was spot on. I get it now. Thanks!

  • @chaop4o878
    @chaop4o8784 жыл бұрын

    I am so close to start crying of joy. I just spent so long trying to figure this out and then I found this video. Thank you so much. Honestly, you make my favourite tutorials.

  • @HamKibz
    @HamKibz3 жыл бұрын

    It took me only 27 minutes to understand a simple concept that has been overly complicated by some bloggers. Thanks man, that was great.

  • @ryanlarge6296
    @ryanlarge6296 Жыл бұрын

    Thank you Kyle for another great video!! Especially by making some confusing topics much clearer and understandable in such little time. I think that many of us could benefit a thousand times more from this jwt knowledge if you created a sequel to this video, or even simply a separate video all together explaining how this backend logic is tied in with the front end via a js framework or keeping it simple like ejs or regular html. There is not a whole lot of good quality educational videos or documentation covering how it can all be connected and implemented into a true fullstack application. It took me a very long time to figure out how to serve my front end as well as authenticate users with jwt using ejs. I would love to see a good video on this from you. Thank you again!

  • @PaweAndruszkow
    @PaweAndruszkow3 жыл бұрын

    this is how code tutorial video should look like! Simply, precize, no overtalking, just exact content we need, very good job!

  • @tinnyw2
    @tinnyw22 жыл бұрын

    Kyle has an amazing talent for teaching and this demystifies a lot of how to implement JWTs on the server end. If I may, one caveat I would add is adding access and refresh tokens in the body payload may be prone to being stolen in an XSS attack and depending on how secure you would like to make your site you might want to instead store them on http-only & secure cookies with a samesite set to at least lax so they're not read by Javascript and easily stolen. Again, this tutorial is on point on so many levels and amazing!

  • @3042640426

    @3042640426

    2 жыл бұрын

    Do you have any solution for that? Thx

  • @rajeshjamnadas
    @rajeshjamnadas4 жыл бұрын

    No nonsense just straight to the point. Clear and precise explanation. Thanks you for time for a good tutorial, cheers!

  • @majoulwa
    @majoulwa4 жыл бұрын

    Hi, I would particularly like to praise your clear explanations and your super clear pronunciation. So it is very easy to understand, even for someone like me, who doesn't have a lot of experience in English and who often has trouble following English-language content with a strong accent. Really great!

  • @samgram5122
    @samgram51224 жыл бұрын

    You blink a lot, but holy crap! You speak so clearly and teach so well without any cuts! AMAZING! Thank you so much!

  • @mykolakecha
    @mykolakecha2 жыл бұрын

    This is probably the first time I'm writing a comment to a video. The reason - just wanted to acknowledge the quality of content. Especially how nice & simple everything is explained.

  • @Bruno87198
    @Bruno87198 Жыл бұрын

    Exactily what I need! You just got a new subscriber. Simple, direct to the point, no use of database and other things, really direct to the point! Saves a lot of time. Thank you!

  • @divyanshubhatnagar4601
    @divyanshubhatnagar46013 жыл бұрын

    Have to say this was short and loaded with information. I really liked the part where you also explained the Auth and Resource server. Really appreciate the content :)

  • @joonwantsdat
    @joonwantsdat3 жыл бұрын

    I'm from South Korea, Kyle explains in a concise and straight plus simple easy way which makes me understand way better than Udemy courses.

  • @michelkazi3112
    @michelkazi31124 жыл бұрын

    I'm using sails JS and their documentation is a hit or miss with a lot of things. They also have support for sessions instead of JWT. Your explanation and walkthrough were so nicely made that I was able to translate the logic of signing and verifying JWT into helpers for my project. Thank you!

  • @raisedbyreels
    @raisedbyreels2 жыл бұрын

    Yeah, I appreciate tutorials like this, a perfect blend of explanation and implementation. Thanks a million!

  • @drteeth11
    @drteeth114 жыл бұрын

    Yoooo, I just found your channel this week and wanted to let you know I love your content. Super informative, clear explanations, all around great videos. Keep up the good work!

  • @WebDevSimplified

    @WebDevSimplified

    4 жыл бұрын

    Thank you so much! I hope my future videos are just as useful.

  • @BrunoWinck

    @BrunoWinck

    4 жыл бұрын

    same :) feeling very lucky

  • @lahiruudayanga5989
    @lahiruudayanga59894 жыл бұрын

    Damn this is amazing. Wasted 4 hours watching shitty videos and then came through this. Just 30 mins and everything well explained on point. Thanks a lot bro. You got a new subscriber!!!

  • @WebDevSimplified

    @WebDevSimplified

    4 жыл бұрын

    Thank you so much!

  • @lordrampenthump422
    @lordrampenthump4222 жыл бұрын

    Its really hard to explain how valuable this channel is to me. Thank you for existing

  • @spetsnaz_2
    @spetsnaz_23 жыл бұрын

    Man! every video of yours are most simplified on the web one could ever find.....Great work

  • @garrafromsand
    @garrafromsand3 жыл бұрын

    Very distinct skill of explanation, could not be more lucid than this, 2 days of here and there in 20 min

  • @SaadShah1133
    @SaadShah11332 жыл бұрын

    I tried to implement JWT by watching different tutorials but i couldnt understand it, your video was the only video i understood, best node js videos keep it up; great work

  • @nithigd1014
    @nithigd10142 жыл бұрын

    Thank you for explaining complex concepts in very simple and straight forward way I watched many of your videos and I learnt a lot of things that no body could teach in 1 video but you are way of explaination is awesome, you are one of the best teacher in the universe, thank you so much :)

  • @juhandvan
    @juhandvan3 жыл бұрын

    Kyle is a really good teacher. His tutorials helping me a better developer.

  • @farisfajar6982
    @farisfajar69823 жыл бұрын

    Thanks youtube for recommend this channel. I just started to learn programming two weeks ago and find your channel. It is great content for me even i still did not really understand it most of the part so i need to learn a lot from the scratch.

  • @santhanamelumalai8025
    @santhanamelumalai80253 жыл бұрын

    Thanks for the video, I never saw tutorial video without skipping its part, but you broke that with the great way of story telling. Very helpful video.

  • @raicubogdan8078
    @raicubogdan8078 Жыл бұрын

    i love how effortless and efficient you explain everything. and all the tools you use are really cool and easy to setup. thanks!

  • @XiagraBalls
    @XiagraBalls2 жыл бұрын

    Your tutorials are some of the best on YT and I watch a LOT of programming tutorials! 👍🏻👍🏻👍🏻👍🏻👍🏻 🌟🌟🌟🌟🌟

  • @scigama71
    @scigama713 жыл бұрын

    i echo the sentiment that i have learned more with this video then reading books for hours.. Well done :)

  • @igors1208
    @igors12083 жыл бұрын

    The greatest video about jwt implementation on node i've found at internet! Thanks a lot!

  • @SavijCoder
    @SavijCoder10 ай бұрын

    I know this is kind of older, but great presentation, very clear! I have a similar video for doing this in c# (also pretty old), but love how you explained it all here. Thanks!!

  • @debmallyabhattacharya4394
    @debmallyabhattacharya43944 жыл бұрын

    This lives up to its name. Truly simplified. 💙

  • @brianchandler3346
    @brianchandler33463 жыл бұрын

    The absolute clearest tutorial I've ever seen on the topic. I wish I had found this earlier.

  • @higherpurpose1212

    @higherpurpose1212

    2 жыл бұрын

    This is the cleanest for me: kzread.info/dash/bejne/i6OXtNNme8jZc7A.html

  • @atsglobalservices6136
    @atsglobalservices6136 Жыл бұрын

    God bless you dev. This tutorial was fantastic! I understand what you're saying. You don't dilute it with unnecessary jargon. Thank you very much.

  • @haha-eg8fj
    @haha-eg8fj4 жыл бұрын

    That Rest Client plugin is so useful! Works like a charm.

  • @lautaro3365
    @lautaro33653 жыл бұрын

    Dude this was the best video I've seen about JWT and how easy you made it to implement.

  • @quietnix
    @quietnix3 жыл бұрын

    Man, this is the most efficient tutorial on the topic. Where is your applause button dude.

  • @VishalKumar-dv6qj
    @VishalKumar-dv6qj2 жыл бұрын

    Everything was straight-forward and on-point. One question arises - Why we need to create a refresh token when we can delete the previous access token when user logs out? In that way he will not be able to use that access token forever

  • @solofaxum
    @solofaxum4 жыл бұрын

    Bro you are the best. That is all I can say. you simplify the complex. ...keep it up.

  • @number1neek
    @number1neek3 жыл бұрын

    Great video as always! Just wanted point out that what's being covered here is called authorization, not authentication. Authentication is when you confirm a user's identity and authorization is giving that user access to parts of the website

  • @dragmove
    @dragmove3 жыл бұрын

    This video is perfect for me to understand a concept of JWT token and refresh token. I really appreciate it. Thanks Kyle. :)

  • @alexanderzharkov6953
    @alexanderzharkov69532 жыл бұрын

    Thank you, Kyle, for this informative content. I filled many gaps watching your videos and following your advices

  • @qintotgroup
    @qintotgroup Жыл бұрын

    Where have you been all my life Bro. --- THANK YOU for making my job eaaaaaaasy.

  • @daniloespinozapino4865
    @daniloespinozapino48652 жыл бұрын

    You did a really good job with this video dude. Simple and clean.

  • @winken2666
    @winken26662 жыл бұрын

    I am very grateful for this tutorial, thank you! My hobby project is one step closer to not being a hobby project.

  • @natyragashi982
    @natyragashi9822 жыл бұрын

    Thank you man, you are one of the rarest who gives real solutions

  • @codeforlife9513
    @codeforlife95133 жыл бұрын

    Kyle your video inspires me to learn more...and makes easy to understand all the aspects. Thank you so much.

  • @lucaslorenzo6249
    @lucaslorenzo6249 Жыл бұрын

    this is amazing, the way you explain all this concepts make it look easy

  • @AwkworldStudios
    @AwkworldStudios4 жыл бұрын

    Thanks for making this! Fun fact for anyone else watching: you can configure dotenv from your package.json scripts so that you don't have to write require in every file by using the -r flag and dotenv/config like so: "scripts": { "dev": "nodemon -r dotenv/config index.js" },

  • @vinaydixit81

    @vinaydixit81

    4 жыл бұрын

    Everything is good. But i would suggest you to be little slow when you do the code.

  • @nejitawo9657
    @nejitawo96574 жыл бұрын

    In just 30 mins i've learned what a ton of books couldn't explain clearly.

  • @juraev0056

    @juraev0056

    4 жыл бұрын

    You must be reading a wrong book

  • @hagenlens1403

    @hagenlens1403

    4 жыл бұрын

    @@juraev0056 Probably

  • @snoowwe

    @snoowwe

    4 жыл бұрын

    Sometimes you just need to see it in action to understand it. I learn math better by example than by reading theory.

  • @jawad9757

    @jawad9757

    4 жыл бұрын

    Is reading books about programming a thing? I mean it would be good for something like assembly or c or c++ but defo not for anything that is related to js

  • @juraev0056

    @juraev0056

    4 жыл бұрын

    @@jawad9757 I think it is good to read about best practices and design patterns regarding any programming language

  • @himbary
    @himbary4 жыл бұрын

    Amazing quality, thank u. Just watched your jwt intro.

  • @buhlemwanza632
    @buhlemwanza6322 жыл бұрын

    God Bless you man, this is great within 30 minutes JWT and auth isn't mystery anymore, keep it up, you're going to help a lot of people. God Bless you!

  • @vladstanciu5923
    @vladstanciu59234 жыл бұрын

    Really nice video, i just leared all I needed to know about jwt in order to use it in my project. Thanks a lot dude! Really big thumbs up

  • @armaandhanji2112
    @armaandhanji21124 жыл бұрын

    I LOVE anything you make related to Node.js. Thanks always

  • @WebDevSimplified

    @WebDevSimplified

    4 жыл бұрын

    Thank you! I'm really glad you enjoy my node videos because I love making them.

  • @AbhishekKumar-vl3cb
    @AbhishekKumar-vl3cb3 жыл бұрын

    Have a good day you too...👍🎊 You just SIMPLIFIED my WEB DEV query in few minutes... ❤️🙏

  • @LoveYourKitties
    @LoveYourKitties4 жыл бұрын

    Great stuff on JWT! I needed this info for my current project at work, and this came in extremely handy! Subbed!

  • @jonnjon1
    @jonnjon1 Жыл бұрын

    I spent days trying to implement this with passport and didn't succeed. But with your help, I managed to do the same in a couple hours , Thanks a lot!!!

  • @ghilmanfatih9751
    @ghilmanfatih97512 жыл бұрын

    certified beginner-friendly enlighten my noob jwt knowledge in less than an hour

  • @aubz9924
    @aubz99244 жыл бұрын

    Kyle, it would be amazing if you could make a video on how to handle JWTs on the client-side, particularly in React, in order to close the loop on this topic. As always, awesome video :)

  • @aspected

    @aspected

    4 жыл бұрын

    I second this! I think Ben Awad made a video about that but doesn't go into much detail

  • @robertjif6337

    @robertjif6337

    4 жыл бұрын

    I want to see this too, wanna know if what I'm implementing is actually correct

  • @Robd515

    @Robd515

    4 жыл бұрын

    Funny, I'm coming to this video because I know how to implement it with React and not without it. I learned through Brad Travery so you may want to look through his videos.

  • @doberman7

    @doberman7

    3 жыл бұрын

    @@Robd515 could you share an URL?

  • @adityanair3566

    @adityanair3566

    3 жыл бұрын

    @Kyle, please see this comment! Awesome work man, you are giving immense value to society.

  • @eduardotavares76
    @eduardotavares763 жыл бұрын

    The best JWT video ever! You are amazing! Keep doing things like this.

  • @techable7524
    @techable75244 жыл бұрын

    Superb tutorial, video and sound! It's rare to find such quality. Subscribed and looking forward to more of your content.

  • @WebDevSimplified

    @WebDevSimplified

    4 жыл бұрын

    Thank you so much! I hope the rest of my videos are just as helpful.

  • @DoubleDYouTube
    @DoubleDYouTube2 жыл бұрын

    This video cleared up a lot of things regarding JWT. Thanks a lot!

  • @antontrofymchuk3428
    @antontrofymchuk34283 жыл бұрын

    It is just awesome. Unbelievable clear and useful explaining. So many thanks to you!

  • @mokroargra7277
    @mokroargra72774 жыл бұрын

    Nice video man, just found your channel. You explain things very well. I didn't have any trouble following what your doing.

  • @shikharsubedi
    @shikharsubedi4 жыл бұрын

    thank you so much for the clear and concise explanation. I am looking forward to watching more videos from you.

  • @arshadsiddiqui9071
    @arshadsiddiqui9071 Жыл бұрын

    Thanks man. I'm at a place where I'm essentially learning an all new stack and feel like I'm in tutorial hell. These are so efficient and make me feel like I'm close to begin finally working in it. (My usual experiment until it works just isn't working sadly)

  • @Tibo437
    @Tibo4372 жыл бұрын

    Thanks a lot from France for your video, this is so simple doing things with your explainations, please never stop ;)

  • @dericbytes
    @dericbytes Жыл бұрын

    I always pick up something new from your videos. Thanks

  • @user-dz4lw3yp1f
    @user-dz4lw3yp1f6 ай бұрын

    Excellent video. Probably one of the best explanations I have seen. Also, fast - in a good way.

  • @scu8a
    @scu8a3 жыл бұрын

    Thank you for the quality tutorial. You're clear-spoken, and just the right speed for learning. At one point, I thought "This guys IQ must be over 140" - BTW, this is the first video of yours I watched. I found this video when I did a google search for "web token authentication". Again, very nice work.

  • @princebillygrahamkarmoker2122
    @princebillygrahamkarmoker21223 жыл бұрын

    Best tutorial on JWT token. You are straight forward and that's why I have already subscribed to your channel.

  • @viktorlernt6063
    @viktorlernt60632 жыл бұрын

    Thanks Kyle, very helpful to learn using JWT with JavaScript!

  • @shambashibmajumdar1268
    @shambashibmajumdar12682 жыл бұрын

    Amazing! Your content always fascinates me and I learnt many things from you man!

  • @krunalchauhan5780
    @krunalchauhan57803 жыл бұрын

    When I feel to buy any paid course then your video motivate me to save my money ❤️

  • @lings628
    @lings6283 жыл бұрын

    Amazing content! You teach us so much in 30 mins at the right pace and the right way. Thank you so much!

  • @user-nj1pg1ek2y
    @user-nj1pg1ek2y4 ай бұрын

    Thank you very much, Kyle. Your video helped me find a job. Thanks for sharing.

  • @rosikun
    @rosikun3 жыл бұрын

    Thank you , i think i need to watch few more times, but it help me to understand a lot

  • @ConorBailey
    @ConorBailey3 жыл бұрын

    Kyle. Your videos are so helpful. Thanks so much.

  • @bobbyboxer2664
    @bobbyboxer26642 жыл бұрын

    Awesome video! Thank you for taking the time to do this type of content 🙌🙌

  • @denibegaj4564
    @denibegaj45643 жыл бұрын

    Thanks, coming from the world of ASP.NET this was piece of cake. Dudes over there make it look like rocket launching, when it actually is a very simple mechanism.

  • @ni_kabiu_john
    @ni_kabiu_john Жыл бұрын

    Who said pretty men can't code... man thanks sooooo much for this.. i 'have been afraid of backend dev, but now i learning smoothly..

  • @JamesQQuick
    @JamesQQuick3 жыл бұрын

    You're the JWT mastermind :)

  • @chitrangsharma
    @chitrangsharma3 жыл бұрын

    Best programming ASMR channel 💓

  • @JannisAdmek
    @JannisAdmek2 жыл бұрын

    You have such a fantastic way of teaching!

  • @borisnekezov6620
    @borisnekezov66202 жыл бұрын

    Thank you for that great video Kyle! Really usefull and well explained!

  • @LuisPerroneF5
    @LuisPerroneF54 жыл бұрын

    Great video Kyle. Straight to the point! 👍

  • @BruceArmstrong09121997
    @BruceArmstrong091219973 жыл бұрын

    Owow I just realised I clicked like button while watching just like natural action I never like most videos I see in general I must have instinctively like your videos!

  • @t.s.s.chandana9909
    @t.s.s.chandana99094 жыл бұрын

    Really great videos! Awesome explanation! Thank u so much :)

  • @unsignedchar000
    @unsignedchar0003 жыл бұрын

    Great pacing, great delivery. Well done!

  • @SimoneGesualdi
    @SimoneGesualdi5 ай бұрын

    Thank u for your tutorials Kyle!

  • @pranjalsinghkatiyar4972
    @pranjalsinghkatiyar4972 Жыл бұрын

    hey Kyle its good to see such a clear and refined video from backend side ... but could you please make a video explaining how client side uses the Refresh and Access JWT.

  • @fadyibrahim5611
    @fadyibrahim56113 жыл бұрын

    Thanks bro amazing content! God bless you and your family!

  • @umohesther2256
    @umohesther22564 жыл бұрын

    Thank you for this tutorial. You nailed it.

  • @alibarznji2000
    @alibarznji20002 жыл бұрын

    Thank you Kyle, from the bottom of my heart

  • @joicyjoy9658
    @joicyjoy96582 жыл бұрын

    Kyle.....You are a gem for developers....

  • @raymondbyczko
    @raymondbyczko3 жыл бұрын

    Very good! Likewise I subscribed as soon as a recognized the clear approach!

  • @victorhugoolvera8773
    @victorhugoolvera87732 жыл бұрын

    Hello Fireship, I love your 100 seconds videos.