Securely using JWT on the Edge: Authentication in NextJS Middleware!

Поділитися
Вставка
  • Опубліковано 13 січ 2025

КОМЕНТАРІ • 59

  • @hepsko2318
    @hepsko2318 Рік тому +8

    Hi, I liked the protected routing using middelware. But what if, for example, we are using an external backend, you would still recommend using this approach, minus the token verification (because that is already happening on the backend)?

  • @developer_hadi
    @developer_hadi 2 роки тому +8

    Bro please complete the booking system playlist, the idea looks awesome

    • @raymondmichael4987
      @raymondmichael4987 2 роки тому

      Did he abandoned it already!?😢

    • @joshtriedcoding
      @joshtriedcoding  2 роки тому +4

      @@raymondmichael4987 Hell nah this series is going on, just not every video right after another :^)

    • @raymondmichael4987
      @raymondmichael4987 2 роки тому

      @@joshtriedcoding the man himself.
      Just what I wanted to hear.
      We’re all turned in

  • @Sasuke-px5km
    @Sasuke-px5km 10 місяців тому +2

    Hello is there any handling refresh token using axios related to this video?

  • @mohaniya15
    @mohaniya15 2 роки тому +4

    Which snippet extension do you use? I like the way you can just write state and the useState is autocompleted.

    • @aerotheory
      @aerotheory 2 роки тому +1

      He has a video: How to create Custom Snippets in VSCode (with examples)

  • @saharilarshad1628
    @saharilarshad1628 Рік тому

    Useful knowledge.. Hope, next will be NextAuth with the JWT access token Register, Login and User Access Role..!

  • @bongjames2222
    @bongjames2222 Рік тому

    nextjs 인증강의를 검색하던중 찾았습니다. 감사합니다.
    nextjs 를 처음배우는데 영어를 몰라서 자동번역으로 보면서 겨우겨우 따라하고 있습니다.

  • @nuuklu3189
    @nuuklu3189 Рік тому +2

    well explained. is there a github link ?

  • @sagart00100
    @sagart00100 Рік тому

    if we have to show user data in /dashboard page , how can we do that
    we can do so by getServerSideProps
    but what if we have to show userData in Navbar(email) , /profile page
    for client-side we can use useEffect
    BUT
    what if we have to show data in Navbar, dashboar,profile page on the very first page load

  • @ghalitsar2730
    @ghalitsar2730 2 роки тому +2

    awesome video ! , can u implement refreshToken on the next video ... cant wait for another video from u

    • @alowais900
      @alowais900 Рік тому

      Yes please! Agreed, a refreshToken would be awesome.

  • @rendivs
    @rendivs 5 місяців тому

    You have saved my life josh :)

  • @rizkiduck
    @rizkiduck Рік тому +1

    Thank You. this is very petrified doing authentication in middleware.
    but something strange happened to my nextjs app in production mode. I logged out and changed the maxAge in the serial cookie to -1. cookies deleted successfully but i can still access admin page. sometimes the data displayed is data from other users at different levels who have logged in on their respective devices. Please help and sorry for my english

  • @ambrosebeavers
    @ambrosebeavers Рік тому

    Hey Josh I notice that when I redirect the upload still shows the path of the previous page. Any way to fix that

  • @timur.shhhhh
    @timur.shhhhh 8 місяців тому

    what does Edge mean, I often hear it, but I can’t understand it, because English is not my main language, is it like a browser from Microsoft?

  • @justiceessiel6123
    @justiceessiel6123 Рік тому +1

    What is the "on the edge "exactly..

  • @LeagueofLegendMoment
    @LeagueofLegendMoment Рік тому

    hi Josh, your video helpful with me, when i do with my project, it run perfectly in local, but when i deployed on vercel, the middleware not working, it mean the JWT - verifyToken not working, token isn't authenticated. Can you help me.

    • @kamalheydari8612
      @kamalheydari8612 Рік тому

      hey, I'm having the same issue. Have you found any solutions for it?

  • @oopss794
    @oopss794 Рік тому

    6:57
    is using next-auth more secure?

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      next-auth gets a lot of things about web-app security right out of the box and encourages security best practices, such as avoiding using password auth

  • @christianstamati
    @christianstamati Рік тому

    how to can i implement logout? I just need to delete the cookie on client side?

  • @ashankarunaratne3424
    @ashankarunaratne3424 Рік тому

    Hey Josh thanks for this, I'm using this for my new project but I'm having an issue how do I protect dynamic routes? for example I want to protect this route "/customer/[id]"

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +2

      It's easiest to validate the JWT through a middleware and allow a next() only if the token is valid

    • @ashankarunaratne3424
      @ashankarunaratne3424 Рік тому

      @@joshtriedcoding Thanks Josh 🍻

  • @webber5629
    @webber5629 Рік тому

    If user is logged in and if they still wanna access /login then how to redirect them to " /" page

  • @kirielbe
    @kirielbe Рік тому

    Hi, where can I find this example on your github?

  • @vernevens1598
    @vernevens1598 9 місяців тому

    Who is vercel and why would i give a hoot about their best practices?

  • @chamir4614
    @chamir4614 Рік тому

    Where did you get that wallpaper? It's really really cool!

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      Cheers dude, the service providing that was called Wallpaper Engine on Steam

  • @agimalma5321
    @agimalma5321 Рік тому

    bro i haved try this, and i have problem because this not use the next auth to get the session user, my asking is "how to get session user in dashboard ? or how we can show user who login to the app"

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +1

      Within next-auth, you can use the getServerSession or client side useSession for that

  • @dawitminale2775
    @dawitminale2775 Рік тому

    is it the same for next 13
    ?

  • @Mark-lg2qe
    @Mark-lg2qe Рік тому

    Do you have a github link?

  • @raymondmichael4987
    @raymondmichael4987 2 роки тому

    Is it possible to automatically logout the user immediately when the cookie expire? 😊,

    • @developer_hadi
      @developer_hadi 2 роки тому +2

      No but when he try to send a request you can check if his token is expired and if it is, you can logout the user

    • @raymondmichael4987
      @raymondmichael4987 2 роки тому +1

      @@developer_hadi thanks buddy

  • @bongjames2222
    @bongjames2222 Рік тому

    혹시 trpc 를 사용하지 않고 middleware 를 만든 영상도 있습니까?

  • @nguyennam5056
    @nguyennam5056 Рік тому

    Why can not i see you set cookie?

  • @LazyShady
    @LazyShady 2 роки тому

    Dang..Im using normal NextJs and im stuck on the OnSuccess part.

    • @joshtriedcoding
      @joshtriedcoding  2 роки тому +1

      You could return this from the middleware like {success: true, data: ...} and then check for the success property in your trycatch! :D

    • @LazyShady
      @LazyShady Рік тому

      @@joshtriedcoding dude thats such a better idea. Right now im using axios to post formdata to nextApi and waiting for a response 200 to router.push 🫢

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      @@LazyShady cheers man

  • @muhammadijaz6042
    @muhammadijaz6042 4 місяці тому

    Nice video. Please, update it with next.js 14 if convenient. Take care.

  • @riveto_ir
    @riveto_ir Рік тому

    OH GOSH!!! Thanks JOSH :)

  • @jotaroisdarius1918
    @jotaroisdarius1918 Рік тому

    Thank you so much!

  • @aerotheory
    @aerotheory 2 роки тому

    trpc route structure changed.

    • @joshtriedcoding
      @joshtriedcoding  2 роки тому

      Yeah I was a bit confused at first, they did it again

  • @webber5629
    @webber5629 Рік тому

    Code please ?

  • @ambrosebeavers
    @ambrosebeavers Рік тому

    Wonderful!

  • @devotee9606
    @devotee9606 Рік тому +1

    Thanks

  • @cyphermediaschool
    @cyphermediaschool 9 місяців тому

    it woking good .

  • @kevinpuchaicela6737
    @kevinpuchaicela6737 Рік тому

    thansk!

  • @andrebozzato
    @andrebozzato Рік тому

    top!

  • @marcinburzynski8082
    @marcinburzynski8082 Рік тому

    just so you know. `!!"" === false`