Authentication & Refreshing Tokens Implementation

Поделиться
HTML-код
  • Опубликовано: 25 май 2024
  • Implementing JWT access and refresh token authentication with Django & React using the timed interval method.
    Source Code: github.com/divanov11/refresh-...
    Axios Interceptor Method: • Refreshing Tokens With...
    Timestamps
    00:00 - Intro
    4:15 - Setting Up Django Project
    12:15 - Adding Django REST Framework
    15:24 - Adding Simple JWT
    22:00 - Customizing JWT Settings
    23:25 - Access & Refresh Token Lifespan
    24:32- Rotating Refresh Tokens
    26:25 - Blacklisting Refresh Tokens
    30:00 - Customizing Token Claims
    34:38 - CORS Configuration
    38:30 - Setting up React Files
    51:25 - Private Routes
    58:25 - Setting up AuthContext
    1:04:24 - Login User
    1:20:00 - Get user state from local storage on load
    1:29:45 - Logout User
    1:31:30 - Refresh & Rotating Tokens
    1:45:10 - Setting Up User Items in DB
    1:52:20 - Adding Protected Endpoints
    1:54:30 - Rending user items
    2:01:35 - Logout user on fail
    2:04:45 - Refreshing Token on load
  • РазвлеченияРазвлечения

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

  • @theanonymous5268
    @theanonymous5268 15 дней назад +1

    Great Video!
    Just a note for anyone watching the video,
    "If you don't get it, you probably aren't ready for it yet" because Dennis explains pretty well.

  • @gregruiz921
    @gregruiz921 Год назад +40

    This is very high quality content Dennis... thank you for your time and effort put into this production.

  • @mattiepro2494
    @mattiepro2494 2 года назад +8

    This is the second time your tutorials have saved my life! I cannot thank you enough.
    YOU ARE MY HERO!

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

    Thank you so much Dennis! Whenever I need anything related to Django, I just always come to your videos!!

  • @NOTHING-en2ue
    @NOTHING-en2ue Год назад

    you know what there is no teacher that teaches this for free, you're the best teacher i've ever seen ❤

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

    Thank you very much for the awesome content!!
    I have used React combined with firebase and Django (standalone) but never used them together. This video was really informative and helped me migrate my current frontends (Django Templates) to React.

  • @raduciurca
    @raduciurca 2 года назад +3

    For PRIVATE ROUTES: if you aren't redirected to login when you go to the home page from the header link, try wrapping the route tags (private and normal route) with the tag.

  • @llraekll
    @llraekll Год назад +26

    React-Router-dom in video is the previous version, this is for anyone using React-Router-dom v6. The must be wrapped around as shown below




    This works for v6

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

      This is true. But when I try and implement the PrivateRouter and wrap the PrivateRouter in , React breaks because PrivateRouter isn't a Route. Did you find a solution to this?

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

      @@honestoliveoil yaa i too got like that. any fix?

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

      @@munawar1288 dont forget to initialize user variable

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

      @@honestoliveoil
      # BrowserRouter

      ...

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

      sure

  • @kozol7
    @kozol7 Год назад +7

    This is exactly what I have been looking for! Complete and well explained.

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

      i think the jwt token must be decoded only in the server with a private key

  • @jasbirsingh-mv5vh
    @jasbirsingh-mv5vh Год назад +1

    Came here for django authentication, along with the authentication part , this tutorial cleared my context API fundamentals too :)

  • @victoralexandre9653
    @victoralexandre9653 5 месяцев назад +1

    Amazing content, Dennis! Your channel is helping a lot with my first Django+React application. Please continue, really rich video!

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

    Very very very helpful video. Approach and explanations are great. Code is slightly outdated due to updates (router dom v6) but nothing a little research can't fix and you have updated videos on the subject too! Thank you.

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

    What a perfect timing.. amazing .. last night I was looking for this kinda video and after 6 hours I hv seen my Django-guy made it!

  • @MuhammadAyaz-gp7xd
    @MuhammadAyaz-gp7xd 5 месяцев назад

    Bestest Tutorial about JWT with Django on RUclips. Thank you so much sir, for making this premium grade content for free.

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

    This was exactly what I needed. Thanks Dennis

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

    oh dude you saved my life too, i was looking for a tutorial about this with react and django and nothing but i found out this video and just saved my life, thank u so much!!!!!! you're a genious thaaankks!!!!! so much

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

    Awesome lecture. Please watch this 2hr and it will save your whole one day in internet surfing

  • @griftegrd
    @griftegrd Год назад +3

    Thank you so much for this really, really high quality video. Very informative, explanations were on point and even the errores were interesting as it happens to everyone, even someone who knows their game like you (which makes me feel a little better :)) I finally understand the logic of JWT and can implement it in my django/angular project. My best wishes to you, and thanks again for this fine content.

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

    So much covered in one video, thank you !

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

    this is really useful and detailed video on authentication. It helped me a lot . Thanks Dennis.

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

    This is very high quality content. Very appriciated Thanks Dennis From INDIA, KERALA, THRISSUR, KODAKARA

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

    I really was looking for any tutorial that explains how to apply the refreshing token, but no luck .. anyway you are a legend thanks a lot

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

    Amazing video Dennis, really enjoyed it ♥

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

    Thanks Dennis! Amazing tutorial... Congrats from Paraguay!

  • @zhe-jiazhang9535
    @zhe-jiazhang9535 Год назад

    thank you very much. I learn JWT just in three day by your video.

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

    this is very valuable and thank you for explaining things thoroughly!

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

    beautiful tutorial man i love it been looking for this for while now

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

    I almost never like videos, but ty bro you deserved it too much. I f*** love react + django and you just made everything for me so simple.

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

    Great content, format and quality!!

  • @017m.shahzaibafzal4
    @017m.shahzaibafzal4 2 года назад +2

    Thanks Dennis Sir. You are my Best teacher.

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

    Very Very good in-depth auth tutorial. Thank you. this is what the people need !
    Suuuuuubscribed !

  • @Andremzsptm
    @Andremzsptm 2 года назад +18

    That's exactly what I need. Thanks

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

      Lol I was about to post that but I'm 8 months late.

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

    Just what i was looking for + more. thanks!

  • @user-mo9kt1hr3d
    @user-mo9kt1hr3d Год назад +1

    좋은 강의 영상 감사합니다 :)

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

    i was looking for exactly this!!
    thank you so much!!

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

    you saved my life of frustration thank you Dennis.

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

    Thank you so much. I was really struggle for this

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

    very sophisticated course, included with beginners mistakes
    (False, so on..) however I bought all of your courses, but sometimes just funny, but big respect you are trying to show us production ready things, not just useless , common educational apps

  • @joaoarthurbandeira
    @joaoarthurbandeira 10 месяцев назад +6

    Hey Dennis! Excellent tutorial, as always!
    Can you also show us how to do registration and also how a logged in authenticated user can do post requests to create/update notes?
    Cheers, bro!

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

    Thanks Denis.. You have really been helping career

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

    Just what I needed. Thanks!

  • @jamesthomason4788
    @jamesthomason4788 2 года назад +8

    Hi everyone! if you are having trouble with at 49:50 with Route component.... component was replaced in favor for element! I also had to wrap my Route tags in a Routes tag, so it would look more like.

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

    Thank you very much for teaching this. I learned a lot from videos.

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

    Learning a ton! Thanks so much

  • @winter8476
    @winter8476 Год назад +3

    Replace components = {HomePage} to element={} do the same for login and then make you wrap the in a parent .
    Import from the 'react-router-dom'.... any confusion reply with your issue and also Note that in v6 of react Routes Redirect has been replaced with Navigate so just swap and it would work

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

    Amazing work, thank you!

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

    Thank yo so much. Very helpful and informative. Expecially for a beginer like me.

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

    HIGH QUALITY CONTENT!!! THANKS U

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

    thank you for your useful tutorials

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

    Thank You Very Much. This helps a lot!!!!

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

    Thanks for the tutorial! I never worked with tokens and auth, and was really confused about them, but after this video everything became clear.

    • @zenande699
      @zenande699 Год назад +12

      Aren't you supposed to be a Django expert?

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

      @@zenande699 lol

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

    Loved this Video!!
    Thank you :))

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

    Awesome bro, respect

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

    you are the man we need !

  • @usamausman-dev
    @usamausman-dev Год назад +43

    In React-Router-dom version 6 , there is bit difference.... We need to wrap the our tags inside and instead of using component attributes we need to use element as an attribute and pass the component like this .... element= {}

    • @dinokrivic5486
      @dinokrivic5486 Год назад +3

      and also useNavigate instead of userHistory

    • @rizwanriaz8706
      @rizwanriaz8706 Год назад +4

      Using PrivateRoute is also not displaying anything for me..

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

      @@rizwanriaz8706p plz help same problem here

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

      For me I get a problem of invalid token when a user opens his profile but sign in all is ok

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

      Knock knock ○●○

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

    Thank sir. So useful 🤟🏼

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

    My honest thoughts. I knew React Django but i restricted my self to build React +Django projects having authentication because i thought i can not handle authentication . And therefore build only projects with django templating language . Finally I got this playlist Thanks man

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

      same went for me in my college project. I had to use django templating since it is so hard to make user authentication in react + django

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

    Great effort, thank you!

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

    Peferct time when i just finished a videos on it to implement on my project

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

    That's what I was looking for, thanks for creating this usefully tutorial you help me alot, honestly you're a life server.
    But I can't wait to see another tutorial like this by using axios

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

    This is perfect, thanks!!

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

    Good job (y)
    Suggestion: You could have used setTimeout instead of setInterval so you don't have to return a clear interval method :)

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

    Thank you for the helpful video. Do you have a video for adding different role permissions for rest frame work?

  • @santanu8899
    @santanu8899 10 месяцев назад +1

    You are the best teacher and I love watching your video.
    It will be very helpful if you make videos on vuejs.
    please 😌 ...

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

    Waiting for it 💙

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

    why it is showing error when the code is exactly sale: "A is only ever to be used as the child of element, never rendered directly. Please wrap your in a ".

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

    Perect video. Thank you a lot

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

    Best of the best!

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

    Nice job boss!!

  • @BekzodToshpulatov-ev3jv
    @BekzodToshpulatov-ev3jv Год назад

    Thank you broo you helped me

  • @user-dg6xw3gl1j
    @user-dg6xw3gl1j 2 года назад +1

    make more video like this for react and backend thank you

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

    thank uuuuuuuuu so much you saved my life

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

    thank you i made this with flutter and django .

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

    Awesome dude

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

    New video on adding refresh with axios interceptors instead of timed updates: ruclips.net/video/16-1mTdGBoM/видео.html. I know a lot of people were asking about this.

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

    thanks for this tutorial

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

    Hey Dennis I'm building an angular application with a drf-api in the back end, which approach should I take for the authentication? Session? Drf built-in token? or JWT? I'm kinda lost

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

    Me:
    *Bunking scool* to attend your videos 😄😆☺

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

    Hey Dennis,
    Thank you this is really helpful. do you have any other video for the registration and forgot password process?

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

    YOU ARE THE BEST❤❤❤

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

    Thank you very much

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

    Just a question, since i'm following your tutorials for django-react notes
    Can I handle authentication, login and registration just from django and after that having it redirect to the react app?
    Like, django serves '/api' and '/admin' routes
    React only fetches from '/api' route in django
    can I set up to be redirected to a '/login' page from django (like an outside page from the notes app) then upon successful login, being redirected to the React app?

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

    thank you nice content.

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

    Thank you!

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

    When creating the private route I am getting [PrivateRoute] is not a component. All component children of must be a or error. I had to wrap my routes in a Routes element because I got another error telling me to do it.

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

    bro u r just awsome

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

    thank you very much

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

    Thanks Dennis!
    Can admin approval be implemented like with‘registration-redux’?

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

    Thank you

  • @zinness
    @zinness 2 месяца назад +1

    Just i want to ask Questions i didn't find another one explain django very good like Dennis i need this for my project the only thing that our project is Mobil application so the front end developed by flutter there is something changed in backend or rest the same

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

    Merci beaucoup!

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

    This was awesome dennis, I have a question what if I want to authenticate user with more than one field, eg. user can generate toke with username and password, or email and password

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

    Hello Dennis, thank you for this video, how do I incorporate password reset, and others with simple jwt

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

    Thanks!

  • @illiak4668
    @illiak4668 10 месяцев назад +2

    Thanks a lot! A very helpful video. The only remark or rather a question. Did anyone face an issue when an "Access" token disappears after multiple pages in different tabs being loaded simultaneously? E.g. one holds Ctrl and clicks on each item of the list. So the 1st and the 2nd item are loaded OK, and the rest end up with a "Login" page.
    I managed to fix it this way: in the file "AuthContext.js": let [loading, setLoading] = useState(true) _CHANGED_TO_ let [loading, setLoading] = useState(FALSE)
    and if(loading){setLoading(false)} ==> _CHANGED_TO_ if(loading){setLoading(true)}

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

    First of all, this is a great tutorial.
    I have two questions
    1. If there are multiple tab windows, won’t they send refresh token request multiple times
    2. I saw blacklist token will be saved in Django database, what happens if table reaches the max limit ID, I mean it’s possible right?

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

    Hi Dennis bro, your doing awesome video ❤, can you please tell me what theme your using in your vs code

  • @Moliya-ix5ib
    @Moliya-ix5ib 2 месяца назад +1

    Hi, how to issue jwt token based on role? For example, student access (5 min), Teacher access (15 min), Admin access (35 min), and access (50 days) if a request comes from a mobile device.

  • @524bartek
    @524bartek 10 месяцев назад +1

    Great video. I was wondering if it is possible to display some error message in LoginPage under form if login function inside AuthContext returns error (for example status 401 = wrong username/password). Currently im using alert, but how can i send error message between two components and display it on LoginPage? I'm new to React, thanks in advance.

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

    thank you
    مرسی