What are Cookies in NodeJS?

Поделиться
HTML-код
  • Опубликовано: 5 фев 2025
  • ► 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

Комментарии • 124

  • @YashAmbekar-j3p
    @YashAmbekar-j3p Год назад +5

    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.😌

  • @pradeeppop8201
    @pradeeppop8201 Год назад +5

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

  • @santoshdhariwal8979
    @santoshdhariwal8979 Год назад +8

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

  • @Solo_playz
    @Solo_playz 10 месяцев назад +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

  • @ageshalbhandare2487
    @ageshalbhandare2487 Год назад +2

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

  • @weforyouweb1165
    @weforyouweb1165 Год назад +22

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

  • @shubhamgupta-bl1tr
    @shubhamgupta-bl1tr 2 года назад +37

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

  • @lillyput2275
    @lillyput2275 11 месяцев назад +3

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

  • @lakshyakhushalani9464
    @lakshyakhushalani9464 Год назад +1

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

  • @sutharjay1
    @sutharjay1 11 месяцев назад +1

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

  • @rohitlochib2300
    @rohitlochib2300 3 месяца назад

    Thank You Sir, It was one of the Best explanation of cookies on youtube.

  • @satyanshgarg9651
    @satyanshgarg9651 10 месяцев назад

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

  • @mma-dost
    @mma-dost 2 года назад +1

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

  • @ravisingh5906
    @ravisingh5906 10 месяцев назад +15

    i can't set cookie by res.cookie

    • @sawaregamer8815
      @sawaregamer8815 9 месяцев назад +2

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

    • @DineshKumar-gt7xm
      @DineshKumar-gt7xm 8 месяцев назад

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

    • @muhammadtaimoor2378
      @muhammadtaimoor2378 7 месяцев назад +1

      Use res.cookies

  • @Muzafar.A
    @Muzafar.A 11 месяцев назад

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

  • @dineshsinghbisht07
    @dineshsinghbisht07 2 года назад +4

    Thanks for the video 🔥✨

  • @mr_singhai9778
    @mr_singhai9778 23 дня назад

    @priyam,
    In Postman, we manually send the token via headers without using local storage or cookies. How can we receive this token in our backend middleware to authenticate the request?

  • @PrathameshSakore-h1i
    @PrathameshSakore-h1i 3 месяца назад +1

    The authorization header is not present by default in the POST request in postman and hence you can get the error: Cannot read properties of undefined (reading 'split') as there's no authorization header present, you have to set the header in the Headers tab manually as "Authorization" and set its value to null so that it can be used further in the middleware functions.

  • @mayankbadika3101
    @mayankbadika3101 11 месяцев назад

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

  • @FaizanShaikh-k3r
    @FaizanShaikh-k3r 15 дней назад

    but when i m sending the cookies to the browser is not storing that cookies after first referesh cookies is not presitent on that browser i m usiing vercel for both front or back domain

  • @iganic7574
    @iganic7574 3 месяца назад

    16:10 what are you trying to do 🤔
    According to mdn
    Fir domain value -
    "Only the current domain can be set as the value, or a domain of a higher order"
    "A cookie for a domain that does not include the server that set it should be rejected by the user agent."

  • @mahendra.k12
    @mahendra.k12 7 месяцев назад +10

    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!

  • @ashishprajapati825
    @ashishprajapati825 Год назад

    Amazing explaination bro ❤👏🏻

  • @Hardik3000
    @Hardik3000 7 месяцев назад

    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

  • @AkashLayal
    @AkashLayal 11 месяцев назад

    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 11 месяцев назад

      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,

  • @imPrathamDev
    @imPrathamDev 2 года назад +5

    can you explain refresh token and access token?

  • @khushichaurasia121
    @khushichaurasia121 3 месяца назад +2

    From where you learn all this so well??

    • @Believeharsh
      @Believeharsh Месяц назад +1

      This is called pure hardworking, he go through all the documenation and dig the google very well.
      That is the problem, everything is available for everyone but our lazy culture........!!

  • @heyOrca2711
    @heyOrca2711 3 месяца назад

    Thank You Piyush For this great video!!! ; )

  • @movocode
    @movocode Год назад

    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).

  • @kanamithra5062
    @kanamithra5062 11 месяцев назад

    Good explanation👍

  • @banothutharun2743
    @banothutharun2743 4 месяца назад

    excellent explanation brother

  • @pallabdandapat1866
    @pallabdandapat1866 8 месяцев назад +2

    22:28 -->changes happen

  • @vishalkumarshaw9208
    @vishalkumarshaw9208 3 месяца назад

    superb bhai...

  • @himanshuarora1910
    @himanshuarora1910 10 месяцев назад

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

  • @Abdullahsiddique-wf2nt
    @Abdullahsiddique-wf2nt 10 месяцев назад

    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

  • @Raj6026
    @Raj6026 Год назад

    Thanks bro..excellent video .really helpful

  • @tarushchandra8993
    @tarushchandra8993 2 года назад +2

    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..

    • @JatinBedi69
      @JatinBedi69 Год назад +1

      Bhai solution mila kya

    • @DineshKumar-gt7xm
      @DineshKumar-gt7xm 8 месяцев назад

      ​@@JatinBedi69did you get any solution?

    • @somyamishra1421
      @somyamishra1421 2 дня назад

      1. Aapke server ko CORS aur cookies ke sahi options enable karne padenge.
      2.Agar aap React.js ya kisi aur frontend se API request bhej rahe hain, to fetch / axios me credentials: "include" add karein.
      3.Kuch browsers (jaise Chrome) default third-party cookies block kar dete hain.
      Chrome me cross-site cookies enable karne ke liye:
      Settings → Privacy & Security → Cookies and site data → Allow third-party cookies
      Agar Chrome me test kar rahe hain to Incognito Mode me test karein kyunki waha extensions aur settings interfere nahi karti.

  • @riser636
    @riser636 2 дня назад

    Do anyone know why browser is not storing the cookie while it works fine with postman. ?

  • @chetu9241
    @chetu9241 Год назад +2

    U got one subscriber ❤

  • @shamunkhatri6754
    @shamunkhatri6754 4 месяца назад

    Really good video but It would be good if you compare localstorage vs cookies which is better, limitations like that.

  • @CodeWavewithShahHussain
    @CodeWavewithShahHussain Год назад

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

  • @Tensor08
    @Tensor08 4 месяца назад

    2:00 what about storing user with their session id in redis instead of db

    • @Fe-ironman
      @Fe-ironman 4 месяца назад

      what is the difference? what does reddis do?

    • @saeedahmed1177
      @saeedahmed1177 24 дня назад

      That is good way

  • @lovelymusic3549
    @lovelymusic3549 2 года назад +1

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

  • @amanmaddhesia120
    @amanmaddhesia120 4 месяца назад

    Too good brother

  • @Rij-k6p
    @Rij-k6p 7 месяцев назад

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

    • @theannonymous1430
      @theannonymous1430 Месяц назад

      Even Google is using cookies and you still have doubt 😂

  • @Rohitkumar-xy7bj
    @Rohitkumar-xy7bj 4 дня назад

    Thank you so much

  • @Ajmal_Hossain
    @Ajmal_Hossain Год назад

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

  • @ajput0018
    @ajput0018 6 месяцев назад

    bhaia do you have short notes of this lecture

  • @jackma9528
    @jackma9528 9 месяцев назад

    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

  • @coderkashif
    @coderkashif Год назад

    Bro you are great>>>

  • @knightcore4062
    @knightcore4062 5 месяцев назад

    im facing problem regarding non existing authorization header in server side gives Cannot read properties of undefined (reading 'split'), though using res.set('Authorization', `Bearer ${token}`); inside handleUserLogin async function to set the valus, help me to debug it any one...

  • @challarashmitha55
    @challarashmitha55 9 месяцев назад

    How can I get a token set in cookies in browser

  • @rztutul8824
    @rztutul8824 7 месяцев назад

    Thank you so much bro

  • @learner5839
    @learner5839 Год назад +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 8 месяцев назад

      Did you find any solution for this problem?

    • @BiGryuuu
      @BiGryuuu 5 месяцев назад

      ​@@DineshKumar-gt7xm did you?

    • @NOVAGAMING_08
      @NOVAGAMING_08 5 месяцев назад

      ​@@BiGryuuu add with credentials: true in your frontend code and in backend use cors ( app.use(cors({
      origin : '*',
      credentials: true,
      }))
      I think this might work for you

  • @abhishekgautam2289
    @abhishekgautam2289 10 месяцев назад

    kaise ho pankaj sir ham bhi yhi se padh rhe😁

  • @amandeep-pg3vb
    @amandeep-pg3vb 4 месяца назад

    I didn't get authorization in req.headers, where am I wrong?

  • @utkarshtenguria3836
    @utkarshtenguria3836 9 месяцев назад

    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 7 месяцев назад

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

  • @gautammali768
    @gautammali768 4 месяца назад

    Bhaiya please make a video on cross site in which authorization header is sent to the backend my malicious website and produce hacking in the backend :)

  • @aazimsheikh279
    @aazimsheikh279 7 месяцев назад

    I am not getting authorization in the headers. Why?

  • @utkarshtenguria3836
    @utkarshtenguria3836 9 месяцев назад

    how we can take user information from tokens Piyush Garg

  • @reactjs-tutorial
    @reactjs-tutorial 5 месяцев назад +1

    how to get this code

  • @RishiRajxtrim
    @RishiRajxtrim Год назад

    Adhyapak Diwas ki Shubhkamnaein! 🙏😇

  • @ApurvaKalvadeSDE
    @ApurvaKalvadeSDE Год назад

    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 7 месяцев назад

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

  • @nishaaa_maurya
    @nishaaa_maurya Год назад

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

  • @jatinsharma3792
    @jatinsharma3792 Год назад

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

  • @ManojTudu-sc5rb
    @ManojTudu-sc5rb Год назад

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

    • @Solo_playz
      @Solo_playz Год назад

      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 8 месяцев назад

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

  • @ArpitJain-kc7bl
    @ArpitJain-kc7bl 8 месяцев назад

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

    • @pratyushpragyey7002
      @pratyushpragyey7002 8 месяцев назад

      It's a way in which bearer token is designed

    • @ArpitJain-kc7bl
      @ArpitJain-kc7bl 8 месяцев назад

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

    • @pratyushpragyey7002
      @pratyushpragyey7002 8 месяцев назад

      @@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 8 месяцев назад

      @@pratyushpragyey7002 Okay brother thanks for clearing it

  • @Ankit-xq3sl
    @Ankit-xq3sl 10 месяцев назад

    Tenks😊 gruudev

  • @snehapatidar3122
    @snehapatidar3122 7 месяцев назад

    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 7 месяцев назад

      Are you checking whether entry is null or not

  • @rishabhkedia9304
    @rishabhkedia9304 7 месяцев назад

    19:35 reponse

  • @fatimaiqra2169
    @fatimaiqra2169 4 месяца назад

    Thanks

  • @ridhamanand8519
    @ridhamanand8519 Год назад

    what are http only cookie ?

  • @KirtanPatel552
    @KirtanPatel552 Год назад

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

    • @prateek_saxena2107
      @prateek_saxena2107 Год назад

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

    • @KirtanPatel552
      @KirtanPatel552 Год назад

      @@prateek_saxena2107 Not yet...

    • @pratyushpragyey7002
      @pratyushpragyey7002 8 месяцев назад

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

  • @gopinathk1485
    @gopinathk1485 Год назад +1

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

  • @ApurvaKalvadeSDE
    @ApurvaKalvadeSDE Год назад

    ye Manish Paul bhai hai kya ??

  • @ishikamalik4183
    @ishikamalik4183 11 месяцев назад

    excellent

  • @nooneknowsme1370
    @nooneknowsme1370 Год назад

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

  • @ibntofajjal
    @ibntofajjal 2 года назад

    Thank's man

  • @GayatriGaikwad-m4e
    @GayatriGaikwad-m4e Месяц назад

    please share the code

  • @lovishduggal9064
    @lovishduggal9064 2 года назад

    Bhaiya ji esse he videos aati rehye gii ?

  • @vinaykumarc4156
    @vinaykumarc4156 18 дней назад

    bhai mene "split" ki jaga "spilt" likh diya aur uss error ko dund ne ke chakkar me mujhe 1/2 ghand lag gaya🥲🥲

  • @shubhamdas6519
    @shubhamdas6519 9 месяцев назад

    Thanks for the video sir

  • @studyplans3783
    @studyplans3783 8 месяцев назад

    bade bahiya m soch kyo nahi pa rha hun😟

  • @Valysis
    @Valysis 8 дней назад

    done

  • @sufiyanbaraskar234
    @sufiyanbaraskar234 8 месяцев назад +1

    Pls provide the source code always

  • @ParashUkheda
    @ParashUkheda 2 месяца назад

    ddd

  • @pradeeppop8201
    @pradeeppop8201 Год назад

    @piyushgarg sir