What are Cookies in NodeJS?

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024
  • ► Master NodeJS Playlist: • Master NodeJS
    In this tutorial video, you will see what are cookies in browsers and two main authentication patterns i.e via Cookies and Headers
    ► Complete Full Stack Web Developer RoadMap 2023: • Complete Full Stack We...
    Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript on the server side, creating server-side applications with JavaScript.
    ► My Website: www.piyushgarg...
    My Gears
    ► My Girlfriend: amzn.to/3WD6FRp
    ► Apple MacBook Laptop: amzn.to/3WBJgQn
    ► Anker USB Hub: amzn.to/3GhZSr0
    ► Blue Yeti Microphone: amzn.to/3YKZ9FT
    ► External 27” Monitor: amzn.to/3Vp3xaO
    ► Logitech MK295 Wireless Keyboard and Mouse: amzn.to/3DuL1bB
    ► Seagate Expansion 1TB External HDD: amzn.to/3QMm5Q8
    ► Tripod: amzn.to/3S4OwK4
    ► Ring Light: amzn.to/3YLf8DR
    Disclaimer: All the links above are affiliate links.
    Social Links
    ► Twitter - / piyushgarg_dev
    ► LinkedIn - / piyushgarg195
    Video Titles
    What are Cookies in the Browser?
    Cookies in Nodejs?
    Authorization Headers
    Cookie-based Authentication
    Tags
    #nodejs #authentication #javascript #expressjs #mongodb #mernstack #developer #api #https #server #javascriptinhindi #webdevelopment #webapp #realtimeapp #serverside #nonblockingio #tech

ความคิดเห็น • 92

  • @mahendra.k12
    @mahendra.k12 หลายเดือนก่อน +6

    If you encounter this error: Cannot read properties of undefined (reading 'split'), Follow the given steps:
    1. first make changes only to handleLogin controller and send token as json instead of setting a cookie.
    2. Now in postman, make POST req to /user/login and generate a token.
    3. Now make change to our middleware functions i.e to checkAuth and restrictLogin middlewares.
    4. And now finally make GET req to homepage and set the authorization header in postman.
    Reason: If you make changes to the middlewares first and then try to generate the token it will result in error because we don't have authorization header during initial token generation and the checkAuth middleware is still executed. Hence generate the token first and then make necesarry changes in the middlewares.
    Hope it helps!

  • @user-qk8oh5td1g
    @user-qk8oh5td1g 7 หลายเดือนก่อน +6

    The thing I love about this playlist is using simple language, very easy to understand and please always give the scenario of how things work at enterprise level in your future video.😌

  • @shubhamgupta-bl1tr
    @shubhamgupta-bl1tr ปีที่แล้ว +15

    Thanks sir taking my doubts..it's clear now

  • @pradeeppop8201
    @pradeeppop8201 ปีที่แล้ว +6

    This tutorial of nodejs is more useful to any other paid tut .
    Thank you so much sir such a amazing series ❤️ 🙌 👏

  • @weforyouweb1165
    @weforyouweb1165 ปีที่แล้ว +19

    Bro you are explaining very deep things in practical superb bro 🎉🎉

  • @lillyput2275
    @lillyput2275 6 หลายเดือนก่อน +4

    Bro just don’t stop posting videos u r just amazing tutor❤

  • @santoshdhariwal8979
    @santoshdhariwal8979 11 หลายเดือนก่อน +8

    Excellent Videos Piyush... Explaining it in such a simple way.. makes it so easy

  • @ageshalbhandare2487
    @ageshalbhandare2487 10 หลายเดือนก่อน +1

    No words, how you explain deep fully, at each word meaning fully explain😊 Thank you, Create An TH-cam channel and share your knowledge📚

  • @lakshyakhushalani9464
    @lakshyakhushalani9464 ปีที่แล้ว +2

    literally no words for uh bro !...excellent explaination 😃😃

  • @user-kl5nf4lw7p
    @user-kl5nf4lw7p 5 หลายเดือนก่อน +1

    that was so useful and deep knowledge for newbie. awesome bro ❤.

  • @sutharjay1
    @sutharjay1 5 หลายเดือนก่อน +1

    Got to know many things this video thank you for the lecture😇😇

  • @dineshsinghbisht07
    @dineshsinghbisht07 ปีที่แล้ว +4

    Thanks for the video 🔥✨

  • @imPrathamDev
    @imPrathamDev ปีที่แล้ว +5

    can you explain refresh token and access token?

  • @ravisingh5906
    @ravisingh5906 5 หลายเดือนก่อน +7

    i can't set cookie by res.cookie

    • @sawaregamer8815
      @sawaregamer8815 3 หลายเดือนก่อน

      use cookie parser and if you work on react and node you need to use cors package

    • @DineshKumar-gt7xm
      @DineshKumar-gt7xm 2 หลายเดือนก่อน

      ​​@@sawaregamer8815I am also not able to set cookies using react. I have used both cookie parser and cors package.

    • @muhammadtaimoor2378
      @muhammadtaimoor2378 2 หลายเดือนก่อน

      Use res.cookies

  • @satyanshgarg9651
    @satyanshgarg9651 5 หลายเดือนก่อน

    Great work, it has compelled me to like and subscribe.

  • @Solo_playz
    @Solo_playz 4 หลายเดือนก่อน +1

    I thought the same even though I used to do the same in my MERN stack projects what shubham has asked
    But Thanks Piyush for getting us more clear on it also I found that OAuth and NextAuth use the same technique while authenticating users on each request they utilize tokens stored in the cookies and get users' data from it!
    Very very useful topic you have covered

  • @mma-dost
    @mma-dost ปีที่แล้ว +1

    Thanks bhaiya for the video tutorials. 🥳🥳🔥🔥🤘🤘

  • @mayankbadika3101
    @mayankbadika3101 6 หลายเดือนก่อน

    Thank you so much for sharing this. Very good explanation :)

  • @movocode
    @movocode 9 หลายเดือนก่อน

    Thank you for this tutorial - you have make an overview video about architecture of SSO (single sign on) authentication - if possible, can you make a full coding tutorial of SSO (basic only will do).

  • @ashishprajapati825
    @ashishprajapati825 7 หลายเดือนก่อน

    Amazing explaination bro ❤👏🏻

  • @kanamithra5062
    @kanamithra5062 5 หลายเดือนก่อน

    Good explanation👍

  • @Raj6026
    @Raj6026 ปีที่แล้ว

    Thanks bro..excellent video .really helpful

  • @unknown-lv8io
    @unknown-lv8io 2 หลายเดือนก่อน

    21:06 but token match karne ke liye database access chahiye hoga na har bar request aane par!!..........to problem to same hi rahi jo aapne video ke starting me kaha tha

  • @rztutul8824
    @rztutul8824 หลายเดือนก่อน

    Thank you so much bro

  • @chetu9241
    @chetu9241 ปีที่แล้ว +2

    U got one subscriber ❤

  • @user-go9bs2mh8f
    @user-go9bs2mh8f หลายเดือนก่อน

    in browser based applications, in industry standard for authentication tokens are sent through cookies or response?

  • @Abdullahsiddique-wf2nt
    @Abdullahsiddique-wf2nt 4 หลายเดือนก่อน

    Agr hum Map or database ko combined use kry tu excess database request ka issue ni hoga, first time jab user login hoga tu map ma bhi or database ma bhi store hoga or getuser ma hum check laga day ka agr user exist krta ha map ma tu database sa query na kry or agr map sa ma ni ha tu database sa query kr kay usko map store krdy for further request verification

  • @pallabdandapat1866
    @pallabdandapat1866 3 หลายเดือนก่อน

    22:28 -->changes happen

  • @himanshuarora1910
    @himanshuarora1910 4 หลายเดือนก่อน

    you should set the headers in ejs files only ,whats the use of creating them if we have to use postman only

  • @Ajmal_Hossain
    @Ajmal_Hossain 6 หลายเดือนก่อน

    Another potential concern might arise when dealing with stateful authentication in the context of load balancing.

  • @coderkashif
    @coderkashif 9 หลายเดือนก่อน

    Bro you are great>>>

  • @lovelymusic3549
    @lovelymusic3549 ปีที่แล้ว +1

    Sir please tell us about new react JS series any idea when it's starting?

  • @rishabhkedia9304
    @rishabhkedia9304 2 หลายเดือนก่อน

    19:35 reponse

  • @Ankit-xq3sl
    @Ankit-xq3sl 5 หลายเดือนก่อน

    Tenks😊 gruudev

  • @tarushchandra8993
    @tarushchandra8993 ปีที่แล้ว +1

    Hi Piyush, maine ek website banai hai jiska server or client different domain pe hai but jab mai sever me cookies ke option me domain ko apne client ke domain pe set karta hu, tab bhi cookie send nahi ho rahi.
    I've also used cors for cross platform sharing. kya browser ka kuch default behavior hota ki third party client par cookie send nahi karna?
    meanwhile maine localstorage me token send kar diya, but mai cookies me token send karna chahta hu..

    • @theycallmejatin
      @theycallmejatin 7 หลายเดือนก่อน +1

      Bhai solution mila kya

    • @DineshKumar-gt7xm
      @DineshKumar-gt7xm 2 หลายเดือนก่อน

      ​@@theycallmejatindid you get any solution?

  • @jackma9528
    @jackma9528 3 หลายเดือนก่อน

    sir in my code it is showing can't read the properties of undefined after i switched to response section after cookie section, i copied exactly your code but it is not working, if someone know please help

  • @CodeWavewithShahHussain
    @CodeWavewithShahHussain 6 หลายเดือนก่อน

    But jwt be to scrent check krna ka liya br br new page reload phr datbase wala sa match krta ha?

  • @abhishekgautam2289
    @abhishekgautam2289 4 หลายเดือนก่อน

    kaise ho pankaj sir ham bhi yhi se padh rhe😁

  • @aazimsheikh279
    @aazimsheikh279 2 หลายเดือนก่อน

    I am not getting authorization in the headers. Why?

  • @learner5839
    @learner5839 10 หลายเดือนก่อน +1

    Sir I am sending cookie by res.cookie and 'm able to see that cookie in network but not in application-->Cookies

    • @DineshKumar-gt7xm
      @DineshKumar-gt7xm 2 หลายเดือนก่อน

      Did you find any solution for this problem?

    • @BiGryuuu
      @BiGryuuu 3 วันที่ผ่านมา

      ​@@DineshKumar-gt7xm did you?

  • @ajput0018
    @ajput0018 หลายเดือนก่อน

    bhaia do you have short notes of this lecture

  • @RishiRajxtrim
    @RishiRajxtrim 11 หลายเดือนก่อน

    Adhyapak Diwas ki Shubhkamnaein! 🙏😇

    • @piyushgargdev
      @piyushgargdev  11 หลายเดือนก่อน +1

      Thank you so much 😄

  • @AkashLayal
    @AkashLayal 6 หลายเดือนก่อน

    Sir i have a doubt because 11:04 you have directly providing user from jwt token but if the user is deleted from database but the user can still access logged in content.

    • @vishnugopalakrishnan9539
      @vishnugopalakrishnan9539 5 หลายเดือนก่อน

      getUser function doesnt "provide" user directly, it decodes the user data that was signed, i.e. id and email, adds it to req.user (code under restrictToLoggedInUser ) and finds that info from the database for each req, you can check the code at router.get('/'..) under staticRouter,

  • @challarashmitha55
    @challarashmitha55 3 หลายเดือนก่อน

    How can I get a token set in cookies in browser

  • @utkarshtenguria3836
    @utkarshtenguria3836 3 หลายเดือนก่อน

    how we can take user information from tokens Piyush Garg

  • @shubhamdas6519
    @shubhamdas6519 4 หลายเดือนก่อน

    Thanks for the video sir

  • @snehapatidar3122
    @snehapatidar3122 2 หลายเดือนก่อน

    why it showing this?
    C:\Users\toshiba\Desktop\codes
    ode js\URL shortcut project\index.js:50
    res.redirect(entry.redirectURL)
    ^
    TypeError: Cannot read properties of null (reading 'redirectURL')
    at C:\Users\toshiba\Desktop\codes
    ode js\URL shortcut project\index.js:50:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    Node.js v21.7.3
    [nodemon] app crashed - waiting for file changes before starting...

    • @rishabhgupta9846
      @rishabhgupta9846 2 หลายเดือนก่อน

      Are you checking whether entry is null or not

  • @jatinsharma3792
    @jatinsharma3792 10 หลายเดือนก่อน

    I am looking for the content on CSRF and CSP Headers in JAVA Filter. If you could provid it that would be really helpful.

  • @utkarshtenguria3836
    @utkarshtenguria3836 3 หลายเดือนก่อน

    but first time in mobile device we have to login how can we send token in request in first time does it not required?

    • @DozSparrow
      @DozSparrow 2 หลายเดือนก่อน

      First time we need to login, after successful login server provide us token and subsequent we use provided token by server to communicate server

  • @ApurvaKalvadeSDE
    @ApurvaKalvadeSDE 6 หลายเดือนก่อน

    if one user logs in, but second user comes and copy your Authorization Bearer token or Cookie..... and that 2nd person then requests in the backend from his own laptop via the copied token/cookie. In this case, how to make it more secure ???? Can you please walk through this scenario ?

    • @Rahul-yr3up
      @Rahul-yr3up หลายเดือนก่อน

      He has said in his video that do not pass exact jwt token in cookie. Encrypt the token before passing it to the cookie

  • @ishikamalik4183
    @ishikamalik4183 6 หลายเดือนก่อน

    excellent

  • @nishaaa_maurya
    @nishaaa_maurya 11 หลายเดือนก่อน

    In last, we use header base authentication, Will it work for browser?
    Because, it is not working for browser in my case.

  • @nooneknowsme1370
    @nooneknowsme1370 9 หลายเดือนก่อน

    this authorization thing got me confused like cookies, tokens, headers and all.

  • @gopinathk1485
    @gopinathk1485 7 หลายเดือนก่อน

    Very useful video Piyush, but it could be helpul if you are teaching in English

  • @sufiyanbaraskar234
    @sufiyanbaraskar234 2 หลายเดือนก่อน +1

    Pls provide the source code always

  • @ibntofajjal
    @ibntofajjal ปีที่แล้ว

    Thank's man

  • @ManojTudu-sc5rb
    @ManojTudu-sc5rb 10 หลายเดือนก่อน

    Hi.. Need your help.. My req.headers does not contain authorization property

    • @Solo_playz
      @Solo_playz 6 หลายเดือนก่อน

      Bro! You have to set your headers on your own
      like this that contain Authorization property here is the example!
      const headers = {
      'Authorization':'Bearer ',
      'Content-Type:'application/json', // just an example property you can add more property as you want!
      }
      now you can pass this header with your fetching methods like fetch or Axios
      Hope you get it

    • @pratyushpragyey7002
      @pratyushpragyey7002 3 หลายเดือนก่อน

      well if you're using postman then you've to set the bearer token by going in headers

  • @KirtanPatel552
    @KirtanPatel552 6 หลายเดือนก่อน

    still I got One error TypeError: Cannot read properties of undefined (reading 'split') if Anyone have solution for this...

    • @prateek_saxena2107
      @prateek_saxena2107 6 หลายเดือนก่อน

      getting same error. were you able to find the solution?

    • @KirtanPatel552
      @KirtanPatel552 6 หลายเดือนก่อน

      @@prateek_saxena2107 Not yet...

    • @pratyushpragyey7002
      @pratyushpragyey7002 3 หลายเดือนก่อน

      because you've to set authorization property if you're using postman by setting bearer token

  • @studyplans3783
    @studyplans3783 2 หลายเดือนก่อน

    bade bahiya m soch kyo nahi pa rha hun😟

  • @ArpitJain-kc7bl
    @ArpitJain-kc7bl 3 หลายเดือนก่อน

    What is the need to send bearer, as it is getting split

    • @pratyushpragyey7002
      @pratyushpragyey7002 3 หลายเดือนก่อน

      It's a way in which bearer token is designed

    • @ArpitJain-kc7bl
      @ArpitJain-kc7bl 3 หลายเดือนก่อน

      @@pratyushpragyey7002 is it just to make code readable or it is compulsory

    • @pratyushpragyey7002
      @pratyushpragyey7002 3 หลายเดือนก่อน

      @@ArpitJain-kc7bl you don't have a choice to include it or not it's just how it's written whenever you'll pass the token in headers it will always be attached with word bearer

    • @ArpitJain-kc7bl
      @ArpitJain-kc7bl 2 หลายเดือนก่อน

      @@pratyushpragyey7002 Okay brother thanks for clearing it

  • @ridhamanand8519
    @ridhamanand8519 7 หลายเดือนก่อน

    what are http only cookie ?

  • @ApurvaKalvadeSDE
    @ApurvaKalvadeSDE 6 หลายเดือนก่อน

    ye Manish Paul bhai hai kya ??

  • @lovishduggal9064
    @lovishduggal9064 ปีที่แล้ว

    Bhaiya ji esse he videos aati rehye gii ?

  • @pradeeppop8201
    @pradeeppop8201 ปีที่แล้ว

    @piyushgarg sir